I've tried a lot of the things already posted on here.
But none of them seem to work.
Can anyone please make for me or help me set up a script to add chat commands into my gamemode?
Thanks in advance.
This script should work:
[lua]ChatCommands = {} -- Create the table to store the commands.
function AddChatCommand(cmd, callback)
for k,v in pairs(ChatCommands) do
if cmd == v.cmd then return end -- If the command already exists then don't add another.
end
table.insert(ChatCommands, {cmd = cmd, callback = callback}) -- Add to the table.
end
function GM:PlayerSay(ply, text)
self.BaseClass:PlayerSay(ply, text)
-- Loop through the table of chat commands.
for k, v in pairs(ChatCommands) do
if string.lower(v.cmd) == string.Explode(" ", string.lower(text))[1] then
return v.callback(ply, "" .. string.sub(text, string.len(v.cmd) + 2, string.len(text)))
end
end
end
-- Test the chat commands script.
function ChatCommandTest(ply, args)
ply:ChatPrint(args)
return ""
end
AddChatCommand("/chat", ChatCommandTest)
[/lua]
Use the chat command "/chat <message>" to test it; it worked fine for me.
I fixed it using something I made myself, I realized what I did wrong.
But thanks, that works too!
Actually Drew post stuff like this, gets their answer, and then says he fixed it himself. I know him a little to well, he is not the type to trust.
Someone's mad.
I used UberMench's one from the other page.
I didn't realize that if I was using search functions it puts HTML codes into the actual code, lol.
Sorry, you need to Log In to post a reply to this thread.