ULX

Author Topic: Chat Triggers  (Read 6244 times)

0 Members and 1 Guest are viewing this topic.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Chat Triggers
« on: July 21, 2013, 01:40:14 AM »
So since I'm pretty new to Lua (I know like... the really, really basic stuff), I would like to know if it's possible to be able to make a phrase said in chat trigger something like tsay.

For example, if player 1 says "Hurr durr". I would like that phrase to trigger ULib.tsay(?) to say: "I LIKE TO HERP DERP".
If this is possible, I would be happy to get some documentation of some sort to guide me to set up this code myself (I have searched the forums a bit, but I'm not sure if I used the right keywords, and if I did, I didn't find anything).

Thanks in advance.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Chat Triggers
« Reply #1 on: July 21, 2013, 02:00:49 AM »
You'll want to hook the PlayerSay base hook. Be very careful though, doing this wrong could potentially break everything else that uses it, including all of ULX's chat commands.

http://gmodwiki.net/Lua/Hooks/Base/PlayerSay

a quick example of how you'd do your example would be:

Code: [Select]
function HurDerp( ply, text, _ )

if ( string.sub( string.lower(text), 1, 9 ) == "hurr durr" ) then
ULib.tsay( ply, "I LIKE TO HERP DERP")
end

end
hook.Add( "PlayerSay", "HurDerp_Hook", HurDerp )
« Last Edit: July 21, 2013, 05:40:09 PM by MrPresident »

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given