• Chat Commands
    5 replies, posted
I am reasonably new to Lua coding (so sorry if this is a basic mistake!) but I am trying to create chat commands for the addon 'Atmos'. The only issue with this is that I am trying to make a chat command activate the console command 'atmos_dnc_settime <time>' but I keep getting the error: addons/atmos/lua/autorun/server/chatcommands.lua:7: attempt to index local 'args' (a boolean value). Here is the code that I am using in 'chatcommands.lua' Thanks for the help in advance! [LUA] --[[ Main Function ]]-- local function Chat( pl, cmd, args ) cmd = string.lower( cmd ) if ( string.sub( cmd, 1, 5) == "!time" ) then concommand.Run( pl, "atmos_dnc_settime", args ); end end hook.Add ("PlayerSay", "Chat", Chat ); --[[ End of Main Function ]]--[/LUA]
Try this: [code] local function Chat( ply, text, bTeam ) local args = string.Explode(" ", text); local cmd = string.lower(args[1]); table.remove(args, 1); // removes !time if (string.sub(cmd, 1, 5) == "!time") then concommand.Run(pl, "atmos_dnc_settime", unpack(args)); end end hook.Add("PlayerSay", "Chat", Chat); [/code]
[lua] hook.Add("PlayerSay", "Yes", function(ply, text, bTeam) if (text == "!donate") then // open donate shit elseif (text == "!rules") then // Rules! end end)[/lua] this should help you out to figure out what to do [url]http://wiki.garrysmod.com/page/GM/PlayerSay[/url]
[QUOTE=G4MB!T;45522281]Try this: [code] local function Chat( ply, text, bTeam ) local args = string.Explode(" ", text); local cmd = string.lower(args[1]); table.remove(args, 1); // removes !time if (string.sub(cmd, 1, 5) == "!time") then concommand.Run(pl, "atmos_dnc_settime", unpack(args)); end end hook.Add("PlayerSay", "Chat", Chat); [/code][/QUOTE] Thank you so much! That worked perfectly. I am now going to sit down and look over the code and why it works so that I can learn from this. Thanks again for the help. [editline]28th July 2014[/editline] One more quick question. Could someone point me towards how I could make it so when I type !time in the chat it doesn't display for anyone and just activates the command? Thanks, Miner.
Sure, take a look at this: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_commands/chat_commands.lua.html[/url] It converts !commands to commands that can be seen ( arguments are automatically separated out by spaces ), and commands using / are silent. Just return ""; for it to be silent.
[QUOTE=Acecool;45522484]Sure, take a look at this: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_commands/chat_commands.lua.html[/url] It converts !commands to commands that can be seen ( arguments are automatically separated out by spaces ), and commands using / are silent. Just return ""; for it to be silent.[/QUOTE] Thanks! This will be useful for making my chat commands.
Sorry, you need to Log In to post a reply to this thread.