General > Developers Corner
Chat Triggers
Decicus:
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.
MrPresident:
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: ---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 )
--- End code ---
An Error Has Occurred!
array_keys(): Argument #1 ($array) must be of type array, null given
[0] Board index
Go to full version