• Automatically Run Commands
    13 replies, posted
Hey, I need help with some LUA. I got an admin mod on my server called Citrus. Everytime the server restarts, it doesn't enable the plugins I want so I have to do it manually. Is there a way I can make something in LUA that it would automatically do this everytime the server starts/restarts? Thanks.
[lua]local commands = { "command_1", "command_2 args go here" } hook.Add("InitPostEntity","CitrusCommands",function() for _,v in pairs(commands) do game.ConsoleCommand(v) end end)[/lua] Yeah.
I need 2 commands, the commands are citrus load "Entity Limits" and citrus load "Restrict Tools" Thanks.
[QUOTE=Entoros;23111531][lua]local commands = { "command_1", "command_2 args go here" } hook.Add("InitPostEntity","CitrusCommands",function() for _,v in pairs(commands) do game.ConsoleCommand(v) end end)[/lua] Yeah.[/QUOTE] [lua] local commands = { "citrus load 'Entity Limits'", "citrus load 'Restrict Tools'" }[/lua]
and i put this in autorun/server right? Thanks.
Well?
Yes you do but couldnt you have tested it instead of waiting 16 hours for someone to reply?
Indeed.
I done the following code. [lua] local commands = { "citrus load 'Entity Limits'", "citrus load 'Restrict Tools'" } hook.Add("InitPostEntity","CitrusCommands",function() for _,v in pairs(commands) do game.ConsoleCommand(v) end end) [/lua] And I get the following errors in console. Error, bad server command citrus load 'Entity Limits' Error, bad server command citrus load 'Restrict Tools'
Read this: [URL]http://wiki.garrysmod.com/?title=Game.ConsoleCommand[/URL] (append an \n) Example: [lua]game.ConsoleCommand("say Cake\n")[/lua]
[lua]local commands = { "citrus load 'Entity Limits'\n", "citrus load 'Restrict Tools'\n" } hook.Add("InitPostEntity","CitrusCommands",function() for _,v in pairs(commands) do game.ConsoleCommand(v) end end) [/lua]
[QUOTE=Freze;23250285][lua]local commands = { "citrus load 'Entity Limits --> ' <-- \n", "citrus load 'Restrict Tools --> ' <--\n" } hook.Add("InitPostEntity","CitrusCommands",function() for _,v in pairs(commands) do game.ConsoleCommand(v) end end) [/lua][/QUOTE] Sup with them?
I assume he wants 'Entity Limits' to be counted as one argument. Not sure if that will work though.
It will work fine, "text wdjkadawd" is counted as one argument in Lua.
Sorry, you need to Log In to post a reply to this thread.