concommand.Add( "amg_start", function( ply, cmd, args, string )
if AMG.UseTimer then
print( "AMG.UseTimer must be set to false." )
else
StartMinigame( args[1], args[2] )
end
end)
And I got the error of:
[ERROR] addons/aminigames/lua/autorun/fcp_autorun.lua:20: attempt to call global ‘StartMinigame’ (a nil value)
So I tried getting help and I changed the code up a little and got:
concommand.Add( "amg_start", function( ply, cmd, args, string )
if AMG.UseTimer then
print( "AMG.UseTimer must be set to false." )
else
StartMinigame( ply, cmd )
end
end)
And got the same error. So I’m really lost here. Would appreciate some help.
function StartMinigame( type, length )
print( "Starting minigame!" )
if not table.HasValue( gameTypes, type ) then return end
mgType = table.Random( AMG.miniGames )
theType = type
mgActive = true
for k, v in pairs( player.GetAll() ) do
v.Earned = 0
net.Start( "NotifyPlayers" )
net.Send( v )
end
I’m guessing I would change the code to:
concommand.Add( "amg_start", function( ply, cmd, args, string )
if AMG.UseTimer then
print( "AMG.UseTimer must be set to false." )
else
StartMinigame( type, length )
end
end)
StartMinigame is probably a serverside function you’re trying to call clientside with the command. Make sure the concommand.Add is serverside. Your first code of
concommand.Add( "amg_start", function( ply, cmd, args, string )
if AMG.UseTimer then
print( "AMG.UseTimer must be set to false." )
else
StartMinigame( args[1], args[2] )
end
end)
No, just make sure that the concommand is inside the if statement still. If that checks out, then the only other issue would be that the function is being created after the concommand.
if SERVER then
concommand.Add( "amg_start", function( ply, cmd, args, string )
if AMG.UseTimer then
print( "AMG.UseTimer must be set to false." )
else
StartMinigame( args[1], args[2] )
end
end
end)
[editline]26th August 2014[/editline]
I get the same error when I type it in console but when I restart I get this error from it:
[ERROR] addons/aminigames/lua/autorun/fcp_autorun.lua:24: ‘)’ expected (to close ‘(’ at line 17) near ‘end’
It seems as if the error isn’t even generating from the given code, considering there’s nowhere that needs a ) to close off that isn’t already there. Maybe there’s an error earlier on in the file
If I don’t have it, the command doesn’t work.
I’m really consused.
Here’s my current code:
if SERVER then
concommand.Add( "amg_start", function( ply, cmd, args, string )
if AMG.UseTimer then
print( "AMG.UseTimer must be set to false." )
else
StartMinigame( args[1], args[2] )
end
end
end
end
What you posted earlier, you only had to move the bracket up one line.
[lua]if SERVER then
concommand.Add( “amg_start”, function( ply, cmd, args, string )
if AMG.UseTimer then
print( “AMG.UseTimer must be set to false.” )
else
StartMinigame( args[1], args[2] )
end
end)
end[/lua]