• Print

Author Topic: Chat Commands?  (Read 4291 times)

0 Members and 1 Guest are viewing this topic.

Offline Dog

  • Newbie
  • *
  • Posts: 17
  • Karma: 1
Chat Commands?
« on: December 17, 2014, 07:30:11 pm »
Sorry if this has already been posted, I couldn't find anything by searching.
I've been looking forever on how to make chat commands but I can't seem to find an answer.
I mean chat commands without ULX.
If someone could help it'd be appriciated.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Chat Commands?
« Reply #1 on: December 17, 2014, 07:59:39 pm »
Idk if this is the best way, but I've always done it like this

Code: Lua
  1. function MyCommandF( ply, text )
  2.         if ( string.sub( text, 1, 8 ) == "/suicide" ) then
  3.                 ply:Kill()
  4.         end
  5.         return false
  6. end
  7. hook.Add( "PlayerSay", "MyCommandH", MyCommandF ))
Obviously, you would edit line 2 depending on the command
The second number in ( text, 1, 8 ) being the length of the message in the quotes
And the string being whatever you want the chat command to be

Offline Dog

  • Newbie
  • *
  • Posts: 17
  • Karma: 1
Re: Chat Commands?
« Reply #2 on: December 17, 2014, 08:13:38 pm »
Thanks! I will try tomorrow. The video I saw had a string.lower in it, but it was similar to that.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Chat Commands?
« Reply #3 on: December 17, 2014, 08:18:09 pm »
Lua is case sensitive. For best results, you'd want to use a string.lower("check") == "check" in it, because ChecK is not the same as check.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print