Ulysses
General => Developers Corner => Topic started by: Neku on January 08, 2014, 11:26:21 PM
-
Could someone point out what I'm doing wrong here?
When I run it in-game, it gives me no lua errors, so it's difficult to pinpoint what the issue is.
Don't question my naming.
local adminexception = false -- Will admins still be kicked for using a blocked string?
local sadminexception = false -- Will superadmins still be kicked for using a blocked string?
local noadmincensor = false -- Will admins still be censored? (Neku: Bad idea imo, nya-nya.)
local nosadmincensor = false -- Will superadmins still be censored? (Neku: Still a bad idea, meow.)
local youmeanie = {
"lolipop", -- Remember to place a comma after strings.
"damndude",
"corecheng",
"prinnies" -- Always leave the last string without a comma.
} -- Having many strings blocked will delay chat for everyone and possibly lag the server. They are also not case sensitive.
for k,v in pairs( youmeanie ) do
table.insert( youmeanie, v:upper( ) )
end
local function GetOuttaHere(ply)
RunConsoleCommand("ulx kick" .. ply .. "")
end
local function Riplash( ply, text, public )
local kickpls = nil
local forcetext = nil
local riplash = text
for i = 1, #youmeanie do
local v = youmeanie[ i ]
if ply:IsAdmin() then
if noadmincensor then
forcetext = true
end
elseif ply:IsSuperAdmin() then
if nosadmincensor then
forcetext = true
end
end
if string.find( riplash, v ) and forcetext == nil then
riplash = string.gsub( riplash, v, string.rep( "*", string.len( v ) ) )
kickpls = true
end
end
if forcetext then
return text
else
return riplash
end
if kickpls then
if ply:IsAdmin() then
if adminexception then
else
ply:GetOuttaHere()
end
elseif ply:IsSuperAdmin() then
if ply:IsSuperAdmin() then
else
ply:GetOuttaHere()
end
else
ply:GetOuttaHere()
end
end
end
hook.Add( "PlayerSay", "Meaniecake", Riplash )
-
I'm kinda falling asleep atm, so It's bed time. Here's what I have for you, a modification of what I posted before on another thread. I made censorship into one variable, if you want to change that tell me and I'll look at it in the morning. Everything else is straightforward.
lua\autorun\server
KickWords = KickWords or {}
KickWords.words = {
"lolipop",
"damndude",
"corecheng",
"prinnies"
}
KickWords.admins = false --Kick Admins?
KickWords.sadmins = false --Kick Superadmins?
KickWords.censor = true --Censor words?
hook.Add( "PlayerSay", "Meanie Head", function(ply, text)
local oldtext = text --Remember what they said, for admins sake
for a,b in pairs(KickWords.words) do
if string.find(string.lower(text), b, 1, true) then --Is a word being used?
if KickWords.censor then text = "I said a bad word...." end --What to print if censored.
if (ply:IsAdmin() and not KickWords.admins) or (ply:IsSuperAdmin() and not KickWords.sadmins) then return text end--Tie it all into one line
RunConsoleCommand("ulx", "kick", ply:Nick(), "You Meanie!") --If yes, kick them
ulx.fancyLogAdmin( ply, true, "#A was kicked for saying the following: #s", oldtext or text) --Tell admins they were kicked and what they said.
return text --Return nothing so everyone can't read what was said.
end
end
end )
-
This looks good but maybe put censor, kick, ban all in one script? And do you know if it works for TTT?
-
Haha, thanks Eccid, this was actually meant for the that guy on the other thread.
-
Oh well, it gave me something to do :P
-
This censors but it doesn't seem to kick.
-
General Advice: If you are having issues with code not working and also not throwing errors then start using debug messages.
Essentially place print("something here") code chunks throughout your code (especially inside of loops and if statements) so that you know exactly where you code is going and where it is not going. It is possible that you set up an if statement wrong and didn't notice.
-
This censors but it doesn't seem to kick.
I commented out the line that kicks for testing and didn't change it back until this afternoon when I looked again. Should work fine now.
-
I actually wanted a code that only censors and doesn't kick so this is perfect for me how it is! The only problem is it doesn't adjust for case. For example if the word "test" is censored, the player can say "TEST" and it isn't censored. Also, if they say the word "Test" it isn't censored, or tEst, etc. Would there be a way to fix this?
-
use string.lower (see a lua wiki) to convert the entire message to lower case. Then set all of your key words to lower case.
-
um. Okay I will try...
-
If you don't understand, post what you are using and someone can help you out.
-
I am using Eccid's code from yesterday posted right above on this page.
-
This should work (the change is inside "string.find", btw).
KickWords = KickWords or {}
KickWords.words = {
"lolipop",
"damndude",
"corecheng",
"prinnies"
}
KickWords.admins = false --Kick Admins?
KickWords.sadmins = false --Kick Superadmins?
KickWords.censor = true --Censor words?
hook.Add( "PlayerSay", "Meanie Head", function(ply, text)
local oldtext = text --Remember what they said, for admins sake
for a,b in pairs(KickWords.words) do
if string.find(string.lower(text), b, 1, true) then --Is a word being used?
if KickWords.censor then text = "I said a bad word...." end --What to print if censored.
if (ply:IsAdmin() and not KickWords.admins) or (ply:IsSuperAdmin() and not KickWords.sadmins) then return text end--Tie it all into one line
RunConsoleCommand("ulx", "kick", ply:Nick(), "You Meanie!") --If yes, kick them
ulx.fancyLogAdmin( ply, true, "#A was kicked for saying the following: #s", oldtext or text) --Tell admins they were kicked and what they said.
return text --Return nothing so everyone can't read what was said.
end
end
-
Works great! Thanks so much!
-
I forgot the string.lower, sorry. Thanks decius.
-
Works great! Thanks so much!
No problem!
I forgot the string.lower, sorry. Thanks decius.
It's alright. Got it in the end.
-
Do you see what he did with string.lower?
Try and learn these little things as you go. Being able to customize (if not write your own) lua scripts will set your server apart from all of the many others out there.
Just a protip from someone who's been doing this a very long time.. :)
-
I hope you guys have read the first sentence of my post.
I didn't exactly want someone to right it for me.
Just wanted to know what I did wrong.
-
And from your code, it only seems to work with the first word.
:/
-
And from your code, it only seems to work with the first word.
:/
I just retested it, it works no matter where I put the word, even sandwiched between other words without spaces. Did you change anything?
I hope you guys have read the first sentence of my post.
I didn't exactly want someone to right it for me.
Just wanted to know what I did wrong.
It wasn't exactly my intention to rewrite it for you, it's just hard to discuss back and forth on a forum. I've been learning lua by reading other peoples codes, so I normally just write my own to show other people as help.
-
I changed it so it doesn't display a set message upon trying to use a banned word.
Mine actually censors it.
I did base it off of your's though, so I'm not sure what the issue is.
I don't believe I touched anything related to the array.
-
If you wanna post what I you, I can take a look, and see if I can figure out the problem
-
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?
-
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?
I'll see what I can do. As soon as I can fix my version.
-
If you wanna post what I you, I can take a look, and see if I can figure out the problem
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 )
-
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?
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.
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 )
-
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?
-
Do you know lua, Storm?
If so, use
if ply:IsUserGroup() == "moderator" then
-
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.
-
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.
Make sure that owner inherits from superadmin, it will save you a ton of trouble. Owner can still have its own permissions, but anything that applies to superadmins, will apply to owner. For moderators, change line 17 of my code from:
if (ply:IsAdmin() and not KickWords.admins) or (ply:IsSuperAdmin() and not KickWords.sadmins) then return text end
to this:
if ((ply:IsAdmin() or ply:IsUserGroup("moderator")) and not KickWords.admins) or (ply:IsSuperAdmin() and not KickWords.sadmins) then return text end
make sure ply:IsUserGroup("moderator") has the exact name of your moderator group
-
Hmm it still seems to be censoring all groups.
-
Have you tried my version? (Not the one I posted, the Eccid'ified one, CenKik.)
It's overall the same, plus you can disable kicking and/or censoring.
-
I saw your version but i thought it was a work in process. i didnt know which to take. I have this one all set up, I just need to reconcile the admin-censor thing.
-
Nah, the CenKik version Eccid posted is finished.
-
Thanks Neku! Your script works great and I will be putting it on 11 servers (I assume it will work on all gamemodes). I have to make it not censor moderators so can I just take the "admin" part of the code and change it to moderator? Or will that screw things up? Also, I have the same problem as before - if you censor "hello", it will let "Hello" or HELLO" through. The script is case sensitive.
-
Thanks Neku! Your script works great and I will be putting it on 11 servers (I assume it will work on all gamemodes). I have to make it not censor moderators so can I just take the "admin" part of the code and change it to moderator? Or will that screw things up? Also, I have the same problem as before - if you censor "hello", it will let "Hello" or HELLO" through. The script is case sensitive.
This should be talked about here:
http://forums.ulyssesmod.net/index.php/topic,6938.0.html (http://forums.ulyssesmod.net/index.php/topic,6938.0.html)
Storm, I pretty much added what you needed in the new addon.