• This look right?
    3 replies, posted
Sorry i am not the best at coding could someone see if i did my table right. If i only wanted to do one chat command this would of been easy but i thought it would be nice to add in a table with a bunch of chat commands that are similar. [lua] rtv = { !rockthevote !rtv !RTV !Rtv !RockTheVote !ROCKTHEVOTE /rockthevote /rtv /RTV /Rtv /RockTheVote /ROCKTHEVOTE } hook.Add("PlayerSay", "ChatCommand", function(pl, text, _) local chat = (rtv) if text == "chat" then pl:ConCommand("VoteForChange") end end) [\lua]
No, don't do that. Here, use this as an example: [lua] COMMANDS = { } function COMMANDS:New( cmd, func ) if ( !cmd or !func ) then return end self[ cmd ] = func end function GM:PlayerSay( player, text, public) for k,v in pairs ( COMMANDS ) do local cmd_len = string.len(tostring(k)) if ( string.sub(k, 1, cmd_len) == string.sub(text, 1, cmd_len) ) then local raw = string.sub(text, cmd_len + 1) v( player, raw ); return "" end end Talk( player, 300, player:Nick() .. " says '" .. text .. "'" ) return "" end [/lua] Adding a new command,: [lua] COMMANDS:New( "/all", function( playerr, raw ) for k,v in pairs( player.GetAll() ) do print("[all]" .. raw ); end end) [/lua]
You should probably string.low the command to check incase of case sensitivity.
[QUOTE=LauScript;33193291]No, don't do that. Here, use this as an example: [lua] COMMANDS = { } function COMMANDS:New( cmd, func ) if ( !cmd or !func ) then return end self[ cmd ] = func end function GM:PlayerSay( player, text, public) for k,v in pairs ( COMMANDS ) do local cmd_len = string.len(tostring(k)) if ( string.sub(k, 1, cmd_len) == string.sub(text, 1, cmd_len) ) then local raw = string.sub(text, cmd_len + 1) v( player, raw ); return "" end end Talk( player, 300, player:Nick() .. " says '" .. text .. "'" ) return "" end [/lua] Adding a new command,: [lua] COMMANDS:New( "/all", function( playerr, raw ) for k,v in pairs( player.GetAll() ) do print("[all]" .. raw ); end end) [/lua][/QUOTE] you are really throwing me for a loop with that man haha, i can only make sense of a small fraction of that. Is mine really that far off? i know it worked before i added in the table.
Sorry, you need to Log In to post a reply to this thread.