General > Developers Corner

This thread's OP is a lua n00b

<< < (6/8) > >>

Neku:

--- Quote from: Eccid on January 11, 2014, 01:36:28 AM ---If you wanna post what I you, I can take a look, and see if I can figure out the problem

--- End quote ---


--- Code: ---CenKik = CenKik or {} --Do not edit or remove this line.

CenKik.words = {
"lolipop",
"damndude",
"corecheng",
"prinnies" --Always leave the last one without a comma.
}

CenKik.kik = false --Enable kicking?
CenKik.kikadmin = true --Kick Admins?
CenKik.kiksadmin = false --Kick SuperAdmins?
CenKik.censor = true --Enable censoring?
CenKik.cenadmin = true --Censor Admins? (Neku: Bad idea to not censor.)
CenKik.censadmin = true --Censor SuperAdmins? (Neku: Still a bad idea to not censor.)

local function GetOuttaHere(meanie)
RunConsoleCommand("ulx", "kick", meanie:Nick(), "Attempting to use a blocked word.")
--[[ ulx.fancyLogAdmin( ply, true, "#A got kicked for saying: #s", text ) --It doesn't work. ]]--
end

--[[ local function NoCase( s )
s = string.gsub( s, "%a", function (c)
return string.format( "[%s%s]", string.lower( c ),
       string.upper( c ) )
end )
return s
end ]]--

local function Riplash( ply, text )
local filter = text
local forcetext = nil
CenKik.kikpls = nil
local replace = nil
for k,v in pairs(CenKik.words) do
if string.find( string.lower(filter), v, 1, true ) then --Is a word being used?
if CenKik.censor then
replace = string.rep( "*", string.len( v ) )
filter = string.gsub( string.lower(filter), v, replace )
CenKik.kikpls = true
end
end

if (ply:IsAdmin() and not CenKik.cenadmin) or (ply:IsSuperAdmin() and not CenKik.censadmin) then
forcetext = true
end

if (ply:IsAdmin() and not CenKik.kikadmin) or (ply:IsSuperAdmin() and not CenKik.kiksadmin) then
-- Something goes here. lol
else
if CenKik.kik and CenKik.kikpls then
GetOuttaHere(ply)
end
end

if forcetext or not CenKik.censor then
return text
else
return filter
end
end
end

hook.Add( "PlayerSay", "CenKik", Riplash )
--- End code ---

Eccid:

--- Quote from: Storm on January 11, 2014, 03:52:35 AM ---This will greatly reduce my bans. So I can stop people from posting links, I added "www.", "http", etc. Problem is that I need mods and admins to be able to post the steam link for our group page. Even I can't do it as owner. Is there a way to disable the censor for mods. admins?

--- End quote ---

do you want mods to bypass all censors, or just be able to post web links?


Ok, Ven. I made some modifications using only the code you had there, nothing of my own. I'll walk you through what I did. "function GetOuttaHere" is really un-needed. You can set up what you want to do when the person is decidedly kicked in the same function that checks for the words, so I got rid of that function. Using "return" ends the fuction with the specified results. So, in a script like this, order is everything. It starts off like it did before, except all the local variables except one was removed. You only need to predefine a variable if there's a chance it is called before it's set, which isn't what's happening here. So on line 20, replace is defined as a local variable. Otherwise the censoring code was solid.

After filter has been set as a censored word, we can move on with how to handle censoring and kicking. First it checks if you're an admin or sadmin, and if you're able to be kicked. If you can't be kicked, it then checks if you're censored. If not it returns the text (which finishes the function), else it returns the filter. If you can be kicked, it skips the admin only filter, and treats you like a regular user. Next is where it kicks you, if kick is enabled, you're kicked; all one line. Finally, it checks if the censor is turned on, and if it is it returns the filer, else it returns the real text.

The most important thing to do is make sure what order to check things, and to try and be as little complicated as possible. I try to tie as many things into a single if statement that can be checked together. Here's my edited code below. Tell me if you need to explain anything else I did. I did test this as a user, admin, and superadmin, and it works fine for me.


--- Code: ---CenKik = CenKik or {}
CenKik.words = {
"lolipop",
"damndude",
"corecheng",
"prinnies" --Always leave the last one without a comma.
}
CenKik.kik = false --Enable kicking?
CenKik.kikadmin = false --Kick Admins?
CenKik.kiksadmin = false --Kick SuperAdmins?
CenKik.censor = true --Enable censoring?
CenKik.cenadmin = true --Censor Admins? (Neku: Bad idea to not censor.)
CenKik.censadmin = false --Censor SuperAdmins? (Neku: Still a bad idea to not censor.)

local function Riplash( ply, text )
local filter = text
for k,v in pairs(CenKik.words) do
if string.find( string.lower(filter), v, 1, true ) then
if CenKik.censor then
local replace = string.rep( "*", string.len( v ) )
filter = string.gsub( string.lower(filter), v, replace )
end
end
end

if (ply:IsAdmin() and not CenKik.kikadmin) or (ply:IsSuperAdmin() and not CenKik.kiksadmin) then
if (ply:IsAdmin() and not CenKik.cenadmin) or (ply:IsSuperAdmin() and not CenKik.censadmin) then
return text
else
return filter
end
end

if CenKik.kik then RunConsoleCommand("ulx", "kick", meanie:Nick(), "Attempting to use a blocked word.") end

if CenKik.censor then
return filter
else
return text
end
end

hook.Add( "PlayerSay", "CenKik", Riplash )
--- End code ---

Storm:
Yes I wanted to make the groups moderator, admin, superadmin, owner completely immune, I can just add these other groups consistent with the ULX group names?

Neku:
Do you know lua, Storm?

If so, use

--- Code: ---if ply:IsUserGroup() == "moderator" then
--- End code ---

Storm:
No, Ven, I am afraid I don't know lua but I am trying to pick things up from you guys on this thread and the other thread. I am using Eccid's code but commenting out the kick part, like he did originally. What I want is to just censor all players except mod, admin, sadmin, owner. No kicks or bans for anyone. So all I have to fix is how Eccid's code currently censors those groups.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version