Ulysses

General => Developers Corner => Topic started by: frustratedgamers on January 08, 2014, 04:30:00 PM

Title: Kick when X is said in chat
Post by: frustratedgamers on January 08, 2014, 04:30:00 PM
Was wondering if there is a way to make an addon that would autokick a player if a certain word or predefined phrase was said?
Title: Re: Kick when X is said in chat
Post by: Neku on January 08, 2014, 05:06:59 PM
There is a way, and it's quite simple.

I'll make one for you in a bit.
Title: Re: Kick when X is said in chat
Post by: frustratedgamers on January 08, 2014, 06:23:57 PM
There is a way, and it's quite simple.

I'll make one for you in a bit.

awesome! thank you :D
Title: Re: Kick when X is said in chat
Post by: Neku on January 08, 2014, 06:37:43 PM
Also, what game mode is this for?
Title: Re: Kick when X is said in chat
Post by: frustratedgamers on January 08, 2014, 10:24:58 PM
Also, what game mode is this for?
Would be for prop hunt
Title: Re: Kick when X is said in chat
Post by: Eccid on January 09, 2014, 12:18:51 AM
I'm awake, so here's what I made for you. If you only want kicking to happen, either leave the Banwords table empty, or delete between where it says ban begin and ban end.
Put this in lua\autorun\server\

Code: [Select]
KickWords = KickWords or {}
BanWords = BanWords or {}

KickWords = { --Add what words to be kickable.
"poohead",    --Any added word should be in this format,
"muggle"      --last word does NOT have a comma after it.
}
BanWords = {  --Same rules as above, only for banning
"poopypants",
"nerfherder"
}


hook.Add( "PlayerSay", "Kick For Words", function(ply, text)
--Kick Begin--
for a,b in pairs(KickWords) do
if string.find(string.lower(text), b, 1, true) then --Is a word being used?
RunConsoleCommand("ulx", "kick", ply:Nick(), "Using a banned word.") --If yes, kick them
ulx.fancyLogAdmin( ply, true, "#A was kicked for saying the following: #s", text) --Tell admins they were kicked and what they said.
return "" --Return nothing so everyone can't read what was said.
end
end
--Kick End--

--Ban Begin--
for a,b in pairs(BanWords) do --Same as above, except for banning.
if string.find(string.lower(text), b, 1, true) then
RunConsoleCommand("ulx", "ban",  ply:Nick(), "0", "Using a banned word.") --Ban time is set to 0 for perm, feel free to edit.
ulx.fancyLogAdmin( ply, true, "#A was banned for saying the following: #s", text)
return ""
end
end
--Ban End--
end )

Make sure your admins know what words are in the list and adhere to the rules. It looks bad if your admins are getting kicked for things like this.
Title: Re: Kick when X is said in chat
Post by: Neku on January 09, 2014, 12:26:38 AM
I'm awake, so here's what I made for you. If you only want kicking to happen, either leave the Banwords table empty, or delete between where it says ban begin and ban end.
Put this in lua\autorun\server\

Code: [Select]
KickWords = KickWords or {}
BanWords = BanWords or {}

KickWords = { --Add what words to be kickable.
"poohead",    --Any added word should be in this format,
"muggle"      --last word does NOT have a comma after it.
}
BanWords = {  --Same rules as above, only for banning
"poopypants",
"nerfherder"
}


hook.Add( "PlayerSay", "Kick For Words", function(ply, text)
--Kick Begin--
for a,b in pairs(KickWords) do
if string.find(text, b, 1, true) then --Is a word being used?
RunConsoleCommand("ulx", "kick", ply:Nick(), "Using a banned word.") --If yes, kick them
ulx.fancyLogAdmin( ply, true, "#A was kicked for saying the following: #s", text) --Tell admins they were kicked and what they said.
return "" --Return nothing so everyone can't read what was said.
end
end
--Kick End--

--Ban Begin--
for a,b in pairs(BanWords) do --Same as above, except for banning.
if string.find(text, b, 1, true) then
RunConsoleCommand("ulx", "ban",  ply:Nick(), "0", "Using a banned word.") --Ban time is set to 0 for perm, feel free to edit.
ulx.fancyLogAdmin( ply, true, "#A was banned for saying the following: #s", text)
return ""
end
end
--Ban End--
end )

Make sure your admins know what words are in the list and adhere to the rules. It looks bad if your admins are getting kicked for things like this.

Meh. I was gonna do it, but I ran into issues. (See my Lua n00b thread.)

Thanks for taking my place.
Title: Re: Kick when X is said in chat
Post by: Eccid on January 09, 2014, 12:36:00 AM
Meh. I was gonna do it, but I ran into issues. (See my Lua n00b thread.)

Thanks for taking my place.

:P No problem. I was already awake and had something similar mostly written. Just took a few minutes to polish it.
Title: Re: Kick when X is said in chat
Post by: frustratedgamers on January 09, 2014, 02:10:26 AM
sweet! thank you very much :D
Title: Re: Kick when X is said in chat
Post by: Storm on January 09, 2014, 03:34:43 AM
Can you tell me if this would work in ttt?
Title: Re: Kick when X is said in chat
Post by: Decicus on January 09, 2014, 03:38:31 AM
Can you tell me if this would work in ttt?
It should work as normal, in my eyes.

Isn't it better to use ULib.kick (http://ulyssesmod.net/docs/files/lua/ulib/server/player-lua.html#kick) & ULib.ban (http://ulyssesmod.net/docs/files/lua/ulib/server/player-lua.html#ban)? Instead of running it through the console, I mean.
Title: Re: Kick when X is said in chat
Post by: Eccid on January 09, 2014, 10:30:08 AM
Can you tell me if this would work in ttt?
It will work regardless of game mode.


It should work as normal, in my eyes.

Isn't it better to use ULib.kick (http://ulyssesmod.net/docs/files/lua/ulib/server/player-lua.html#kick) & ULib.ban (http://ulyssesmod.net/docs/files/lua/ulib/server/player-lua.html#ban)? Instead of running it through the console, I mean.

Everytime I use Ulib commands, they fail to work for me, so it's just easier to use RunConsoleCommand.
Title: Re: Kick when X is said in chat
Post by: Megiddo on January 09, 2014, 07:29:21 PM
Everytime I use Ulib commands, they fail to work for me, so it's just easier to use RunConsoleCommand.

We'd love to help you on specific issues... :)
Title: Re: Kick when X is said in chat
Post by: Eccid on January 09, 2014, 08:34:29 PM
We'd love to help you on specific issues... :)

Next time I write something that kicks or bans I'll us ulib commands, and if it messes up post here. It' just easier for me to run console commands :P