Author Topic: PlayerSay running after ULX  (Read 3192 times)

0 Members and 1 Guest are viewing this topic.

Offline StaTiiKxKALEB

  • Newbie
  • *
  • Posts: 17
  • Karma: 2
PlayerSay running after ULX
« 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?
Code: [Select]
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)

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: PlayerSay running after ULX
« Reply #1 on: May 13, 2016, 03:19:33 PM »
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.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline StaTiiKxKALEB

  • Newbie
  • *
  • Posts: 17
  • Karma: 2
Re: PlayerSay running after ULX
« Reply #2 on: May 13, 2016, 06:21:54 PM »
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.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: PlayerSay running after ULX
« Reply #3 on: May 13, 2016, 06:22:14 PM »
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 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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline StaTiiKxKALEB

  • Newbie
  • *
  • Posts: 17
  • Karma: 2
Re: PlayerSay running after ULX
« Reply #4 on: May 13, 2016, 06:28:35 PM »
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?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: PlayerSay running after ULX
« Reply #5 on: May 13, 2016, 06:59:41 PM »
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 or ULibPlayersTargets 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.


« Last Edit: May 13, 2016, 07:01:43 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline StaTiiKxKALEB

  • Newbie
  • *
  • Posts: 17
  • Karma: 2
Re: PlayerSay running after ULX
« Reply #6 on: May 13, 2016, 07:29:21 PM »
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 or ULibPlayersTargets 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.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: PlayerSay running after ULX
« Reply #7 on: May 13, 2016, 07:40:53 PM »
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.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: PlayerSay running after ULX
« Reply #8 on: May 13, 2016, 08:15:07 PM »
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
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming