• Can't get lua script to work
    14 replies, posted
So I have this ID script and I decided to add another command to it, But I can't get it to work [code]function hi() concommand.add("hi" , function() RunConsoleCommand("say Hi!!") end end)[/code] The script is a proof of concept. Since I will change it but this is the base I will be using.
You don't need to put concommand.Add in a function. If you need it to be in a function you would have to call hi() to create the command. You can do something like this [code] concommand.Add( 'hi', function() RunConsoleCommand( 'say Hi!!' ) end ) [/code]
[QUOTE=Ilyaaa;50536259]You don't need to put concommand.Add in a function. If you need it to be in a function you would have to call hi() to create the command. You can do something like this [code] concommand.Add( 'hi', function() RunConsoleCommand( 'say Hi!!' ) end ) [/code][/QUOTE] Because of how hacky RunConsoleCommand is, this won't work. You need: [code] RunConsoleCommand("say","Hi!") [/code] Alternatively a better thing to do is: [code] LocalPlayer():ConCommand("say Hi!") [/code]
[QUOTE=Kevlon;50536353]Because of how hacky RunConsoleCommand is, this won't work. You need: [code] RunConsoleCommand("say","Hi!") [/code] Alternatively a better thing to do is: [code] LocalPlayer():ConCommand("say Hi!") [/code][/QUOTE] I can't seem to get it to work. It gets this error [ERROR] lua/custom/console_commands_shortcuts.lua:10: ')' expected (to close '(' at line 7) near 'end' 1. unknown - lua/custom/console_commands_shortcuts.lua:0 Current script [code] concommand.add("mug" , function() LocalPlayer():RunCommand("say /advert this is a mug, drop 3k or die") end end ) [/code]
[QUOTE=Zohondekids;50536940]I can't seem to get it to work. It gets this error [ERROR] lua/custom/console_commands_shortcuts.lua:10: ')' expected (to close '(' at line 7) near 'end' 1. unknown - lua/custom/console_commands_shortcuts.lua:0 Current script [code] concommand.add("mug" , function() LocalPlayer():RunCommand("say /advert this is a mug, drop 3k or die") end end ) [/code][/QUOTE] You must close something first after opening it before closing anything else, as in you have the right parenthesis ) on the wrong end. That parenthesis is to show that you're done defining the arguments for concommand.Add and your function for the console command is the argument, right? but the function hi() is not part of the arguments. [CODE] function hi() concommand.add("mug" , function() LocalPlayer():RunCommand("say /advert this is a mug, drop 3k or die") end) -- This needs a parenthesis because its showing that you're done telling concommand.Add the proper arguments. This end is telling the end of the function in the console command function args end -- This doesn't need a parenthesis because its not closing arguments. This end is telling the end of the hi() function you first defined in the file [/CODE] I hope you understand as I'm not too good with wording things, I guess. Edit: also I do believe its concommand.Add and not concommand.add right? You'd also replace LocalPlayer():RunCommand() with LocalPlayer:ConCommand() Right?
Why can't you just use 'ply'? That's a perfectly valid player to use the command on? [CODE] concommand.Add( 'mug', function( ply, cmd, args, argStr ) ply:ConCommand("say /advert this is a mug, drop 3k or die") end ) [/CODE] Also, the reason your code wasn't working was because you put an 'end' at a random spot before the function is meant to end
[QUOTE=LittleBigBug;50537202]You must close something first after opening it before closing anything else, as in you have the right parenthesis ) on the wrong end. That parenthesis is to show that you're done defining the arguments for concommand.Add and your function for the console command is the argument, right? but the function hi() is not part of the arguments. [CODE] function hi() concommand.add("mug" , function() LocalPlayer():RunCommand("say /advert this is a mug, drop 3k or die") end) -- This needs a parenthesis because its showing that you're done telling concommand.Add the proper arguments. This end is telling the end of the function in the console command function args end -- This doesn't need a parenthesis because its not closing arguments. This end is telling the end of the hi() function you first defined in the file [/CODE] I hope you understand as I'm not too good with wording things, I guess. Edit: also I do believe its concommand.Add and not concommand.add right? You'd also replace LocalPlayer():RunCommand() with LocalPlayer:ConCommand() Right?[/QUOTE] Replaced it. also now it doesn't give errors but the command doesn't show up in game.
[QUOTE=Zohondekids;50537348]Replaced it. also now it doesn't give errors but the command doesn't show up in game.[/QUOTE] That's because you never RAN the 'hi' function, you only defined it. [editline]17th June 2016[/editline] Also, RunCommand isn't an actual command, you have to use ConCommand instead
[QUOTE=MPan1;50537353]That's because you never RAN the 'hi' function, you only defined it. [editline]17th June 2016[/editline] Also, RunCommand isn't an actual command, you have to use ConCommand instead[/QUOTE] here is the current code [code]function mug() concommand.Add("mug", function() LocalPlayer():ConCommand("say /advert this is a mug, drop 3k or die") end) end[/code]
You still never ran the mug() function [editline]17th June 2016[/editline] You don't even need to put the concommand in a function unless you want to create it later
[QUOTE=MPan1;50537353]That's because you never RAN the 'hi' function, you only defined it. [editline]17th June 2016[/editline] Also, RunCommand isn't an actual command, you have to use ConCommand instead[/QUOTE] then what do I need to change the code to, to fix it.
Either remove or run the function. It's not that hard. If you can't even be bothered to RUN the code you got given, then don't post here. I already gave you a working example before, but you didn't use it. Just do [CODE] mug() [/CODE] To run it. Simple. [editline]17th June 2016[/editline] Also, before you complain about getting 'LocalPlayer() is a nil value' or something like that, just use 'ply' (as I did in the previous example), since that works clientside and serverside.
[QUOTE=MPan1;50537398]Either remove or run the function. It's not that hard. If you can't even be bothered to RUN the code you got given, then don't post here. I already gave you a working example before, but you didn't use it. Just do [CODE] mug() [/CODE] To run it. Simple. [editline]17th June 2016[/editline] Also, before you complain about getting 'LocalPlayer() is a nil value' or something like that, just use 'ply' (as I did in the previous example), since that works clientside and serverside.[/QUOTE] So make mug a separate function? This gave me this error [code]function mug() concommand.Add("mug", function() LocalPlayer():ConCommand("say /advert this is a mug, drop 3k or die") end) end[/code] error:')' expected (to close '(' at line 2) near 'LocalPlayer'
Just try this, I give up: [CODE] local function mug() concommand.Add( 'mug', function( ply ) ply:ConCommand("say /advert this is a mug, drop 3k or die") end ) end mug() -- THIS IS ALL YOU EVER NEEDED TO DO TO SIMPLY RUN THE FUNCTION [/CODE] [editline]17th June 2016[/editline] I don't even know why you're getting that error, I just give up
[QUOTE=MPan1;50537461]Just try this, I give up: [CODE] local function mug() concommand.Add( 'mug', function( ply ) ply:ConCommand("say /advert this is a mug, drop 3k or die") end ) end mug() -- RUN THE FUNCTION [/CODE] [editline]17th June 2016[/editline] I don't even know why you're getting that error, I just give up[/QUOTE] Thanks.. it worked.
Sorry, you need to Log In to post a reply to this thread.