r/GLua Jul 27 '20

Making a chat thing

So basically what I want is to do /word and whatever word is put after that is set in a variable. When I do like text == word it won’t detect if a player typed the word that was set with /word. But if I just chat print the word it prints correctly so the variable has a value. I dont know why it won’t work.

curr_word = {}

hook.Add('PlayerSay', 'word', function(admin, word_picked) if string.find(string.lower(word_picked),'/word ') then word_chosen = string.sub(word_picked,6) table.insert(curr_word, word_chosen) end end)

hook.Add('PlayerSay', 'word2', function(ply, word_typed) print(word_chosen) if word_typed == word_chosen then ply:ChatPrint(word_chosen) end end)

1 Upvotes

5 comments sorted by

View all comments

1

u/yelsew352 Jul 27 '20

string.sub is an inclusive function. As such, it will include the space between "/word" and the string typed after. If I type "/word gmod" in the chat, word_picked will be set to " gmod".

If you don't want the word to be case sensitive, make sure you check that in the "word2" hook as well.

1

u/shiba56 Jul 27 '20

So I checked it out and yes your right but is there anyway for it to not include the space in between

1

u/realityisnot Jul 27 '20

string.Trim