• Print

Author Topic: Need help with some custom commands (minor error in my syntax)  (Read 4384 times)

0 Members and 1 Guest are viewing this topic.

Offline splerge

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Hey guys! made some custom commands on my gameserver. When i reload the server, my gmod instantly gets the error (from this lua file)
"error near 'nuke' on line 69: missing ')'
now as far as i can tell there isn't any missing brackets, so can someone have a look and see why my problem is?
Code: [Select]
----------------------------------------!spawn --------------------------------------------------

function ulx.spawn( calling_ply, target_plys )
local affected_plys = {}
for k,v in pairs(target_plys) do
if !v:Alive() then
nz.Rounds.Functions.ReSpawn(v)
table.insert(affected_plys, v)
else
ULib.tsayError( calling_ply, v:Nick() .. " is alive or spectating!", true )
end
end
ulx.fancyLogAdmin( calling_ply, "#A respawned #T", affected_plys )
end
local spawn = ulx.command( "Utility", "ulx spawn", ulx.spawn, "!spawn" )
spawn:addParam{ type=ULib.cmds.PlayersArg }
spawn:defaultAccess( ULib.ACCESS_ADMIN )
spawn:help( "Spawns target(s)." )

----------------------------------------!points <players> x--------------------------------------------

function ulx.points( calling_ply, target_plys, amount )
local affected_plys = {}
for i=1, #target_plys do
local v = target_plys[ i ]
if v:Alive() then
v:GivePoints(amount)
table.insert(affected_plys, v)
end
end
ulx.fancyLogAdmin( calling_ply, "#A gave #i points to #T", amount, affected_plys )
end
local points = ulx.command( "Utility", "ulx points", ulx.points, "!points" )
points:addParam{ type=ULib.cmds.PlayersArg }
points:defaultAccess( ULib.ACCESS_SUPERADMIN )
points:addParam{ type=ULib.cmds.NumArg, min=1, default=1000000, hint="points", ULib.cmds.round }
spawn:help( "Sets the amount of points for the target(s)." )

---------------------------------------------------------------------------------------------------------

function ulx.ready( calling_ply, target_plys )
local affected_plys = {}
for k,v in pairs(target_plys) do
if !v:Alive() then

nz.Rounds.Functions.ReadyUp(v)
table.insert(affected_plys, v)
end
end
ulx.fancyLogAdmin( calling_ply, "#A readied #T", affected_plys )
end
local ready = ulx.command( "Utility", "ulx ready", ulx.ready, "!ready" )
ready:addParam{ type=ULib.cmds.PlayersArg }
ready:defaultAccess( ULib.ACCESS_ADMIN )
ready:help( "Readies the target(s)" )

--------------------------------------------------------------------------------------------------------
function ulx.nuke()

nz.PowerUps.Functions.Nuke()
for k,v in pairs(player.GetAll()) do
if v:Alive() then
v:TakePoints(500)
end
end
ulx.fancyLogAdmin( calling_ply, "#A dropped a nuke on the zombies!" )
end

local nuke = ulx.command( "Utility", "ulx nuke", ulx nuke, "!nuke" )
nuke:defaultAccess( ULib.ACCESS_SUPERADMIN )
nuke:help( "Nukes zombies without getting points to players, useful for ending rounds" )

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Need help with some custom commands (minor error in my syntax)
« Reply #1 on: July 28, 2015, 04:23:43 am »
A hard error to catch! I had to go through and manually recreate your command in order to find the problem - a missing period in one of the arguments for the ulx.command function on line 11:

Your code:
Code: Lua
  1. function ulx.nuke( calling_ply )
  2.         nz.PowerUps.Functions.Nuke()
  3.         for k,v in pairs(player.GetAll()) do
  4.                 if v:Alive() then
  5.                         v:TakePoints(500)
  6.                 end
  7.         end
  8.         ulx.fancyLogAdmin( calling_ply, "#A dropped a nuke on the zombies!" )
  9. end
  10.  
  11. local nuke = ulx.command( "Utility", "ulx nuke", ulx nuke, "!nuke" )
  12. nuke:defaultAccess( ULib.ACCESS_SUPERADMIN )
  13. nuke:help( "Nukes zombies without getting points to players, useful for ending rounds" )

Fixed code:
Code: Lua
  1. function ulx.nuke( calling_ply )
  2.   nz.PowerUps.Functions.Nuke()
  3.         for k,v in pairs(player.GetAll()) do
  4.                 if v:Alive() then
  5.                         v:TakePoints(500)
  6.                 end
  7.         end
  8.         ulx.fancyLogAdmin( calling_ply, "#A dropped a nuke on the zombies!" )
  9. end
  10.  
  11. local nuke = ulx.command( "Utility", "ulx nuke", ulx.nuke, "!nuke" )
  12. nuke:defaultAccess( ULib.ACCESS_SUPERADMIN )
  13. nuke:help( "Nukes zombies without getting points to players, useful for ending rounds" )
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline splerge

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: Need help with some custom commands (minor error in my syntax)
« Reply #2 on: August 01, 2015, 06:27:28 am »
Thanks a lot, you were exactly right! I also forgot to put the calling variable as "calling_ply", although that wouldnt have caused an error, just would have made the fancy log not work

  • Print