Ulysses
General => Developers Corner => Topic started by: StaTiiKxKALEB on May 13, 2016, 09:27:25 AM
-
I'm running into an issue with blocking chat messages. It's more of a test than something I'd actually use, but it's good for the future. It blocks chat for team chat and public chat but how would I make it so it also blocks it in psay and asay? I'm going to guess the reason why it's still being shown in ULX commands is because ULX is running first, correct?
local function blockCmds( ply, text, public )
if M.Config.EnableBlockedWords then
for _, v in pairs(M.BlockedWords) do
if string.find(text, v) then
return ""
end
end
end
end
hook.Add( "PlayerSay", "blockCmds", blockCmds)
-
I'm running into an issue with blocking chat messages. It's more of a test than something I'd actually use, but it's good for the future. It blocks chat for team chat and public chat but how would I make it so it also blocks it in psay and asay? I'm going to guess the reason why it's still being shown in ULX commands is because ULX is running first, correct?
-snipped code-
Incorrect.
Team and public chat are both chat messages handled by the server itself, and as such they trigger the PlayerSay hook. PSay and ASay are not handled by the server, but instead by ULX, and therefor do not trigger the PlayerSay hook.
The only way I can think to block PSay or ASay would be to recreate the commands yourself, adding in a check for these blocked words and aborting if one is found.
-
Incorrect.
Team and public chat are both chat messages handled by the server itself, and as such they trigger the PlayerSay hook. PSay and ASay are not handled by the server, but instead by ULX, and therefor do not trigger the PlayerSay hook.
The only way I can think to block PSay or ASay would be to recreate the commands yourself, adding in a check for these blocked words and aborting if one is found.
Thanks man, I wasn't trying to imply that ULX was doing it, I was just stating what I thought it'd be. Thanks for the help man. I appreciate it.
-
The only way I can think to block PSay or ASay would be to recreate the commands yourself, adding in a check for these blocked words and aborting if one is found.
ULibCommandCalled (http://ulyssesmod.net/docs/files/lua/ulib/shared/defines-lua.html#ULibCommandCalled) would likely be better.
Return false if blocked word(s) are found in args, command used was "ulx asay" or "ulx psay", do whatever to calling player.
-
ULibCommandCalled (http://ulyssesmod.net/docs/files/lua/ulib/shared/defines-lua.html#ULibCommandCalled) would likely be better.
Return false if blocked word(s) are found in args, command used was "ulx asay" or "ulx psay", do whatever to calling player.
Know of a place where it's used so I can see the efficient way to use it?
-
Not really.
I thought I'd used it in a script before, but realized the one I thought I had not.
I do know now that if I'd continued updating my script, I'd have switched over to using it.
Tinker with it. Create a function that echos it's parameters back to you and call it from the hook.
Also, while looking through my old code, you could use ULibPlayerTarget (http://ulyssesmod.net/docs/files/lua/ulib/shared/defines-lua.html#ULibPlayerTarget) or ULibPlayersTargets (http://ulyssesmod.net/docs/files/lua/ulib/shared/defines-lua.html#ULibPlayerTargets) too.
Basically, Run those hooks and if asay or psay are in the command, check the words list.
See my OLD now broken code on how I used to look for certain commands, then bounce them back to the original caller here
https://forums.ulyssesmod.net/index.php/topic,4507.0.html
Basically, all three hooks mentioned allow you to interrupt the natural flow of ULX (or any ULib addon that calls commands or targets players), then lets you do other stuff, or allow normally.
-
Not really.
I thought I'd used it in a script before, but realized the one I thought I had not.
I do know now that if I'd continued updating my script, I'd have switched over to using it.
Tinker with it. Create a function that echos it's parameters back to you and call it from the hook.
Also, while looking through my old code, you could use ULibPlayerTarget (http://ulyssesmod.net/docs/files/lua/ulib/shared/defines-lua.html#ULibPlayerTarget) or ULibPlayersTargets (http://ulyssesmod.net/docs/files/lua/ulib/shared/defines-lua.html#ULibPlayerTargets) too.
Basically, Run those hooks and if asay or psay are in the command, check the words list.
See my OLD now broken code on how I used to look for certain commands, then bounce them back to the original caller here
https://forums.ulyssesmod.net/index.php/topic,4507.0.html
Basically, all three hooks mentioned allow you to interrupt the natural flow of ULX (or any ULib addon that calls commands or targets players), then lets you do other stuff, or allow normally.
Appreciate it. Thanks man.
-
ULibCommandCalled (http://ulyssesmod.net/docs/files/lua/ulib/shared/defines-lua.html#ULibCommandCalled) would likely be better.
Return false if blocked word(s) are found in args, command used was "ulx asay" or "ulx psay", do whatever to calling player.
Interesting. I wasn't aware you had the possibility of stopping commands via a hook.
-
Interesting. I wasn't aware you had the possibility of stopping commands via a hook.
Yeah, over the years we've had questions about hooking into targeting and called commands, so over time command and targeting hooks have been thrown in.
I've not even played with ULibCommandCalled like I thought I had.
There are four quick easy ones that can be used to modify or add to commands being called.
ULibCommandCalled can prevent if wanted (and of course, do something else if wanted)
ULibPlayerTarget and ULibPlayerTargets can prevent, and even pass back modified target info.
ULibPostTranslatedCommand - do stuff after commands are called