• Print

Author Topic: Need some help with a ULX LUA command.  (Read 54083 times)

0 Members and 1 Guest are viewing this topic.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #30 on: June 26, 2011, 09:24:03 am »
Now I get the following error.

Timer Error: attempt to call a nil value.

Edit: I wish it said what timer is having the error.
I cry every time I see that I am not a respected member of this community.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Need some help with a ULX LUA command.
« Reply #31 on: June 26, 2011, 10:31:29 am »
well.. do you get that error as soon as you use the command, or 120 seconds later?

Change your ulx.zombify function to this. The way you are calling the Spawnzomb function may be trying to pass nul variables to the function.

Code: Lua
  1. See my code below.. this snippit was outdated.
  2.  
« Last Edit: June 26, 2011, 10:45:30 am by MrPresident »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Need some help with a ULX LUA command.
« Reply #32 on: June 26, 2011, 10:35:13 am »
Timers should be formatted like this:
Code: Lua
  1.         timer.Create( "zombSpawn_"..CurTime(), 1, 1,
  2.                 Spawnzomb, pl, pl:GetPos(), pl:GetAngles()
  3.         )
  4.  

Not like you had them:
Code: Lua
  1.         timer.Create( "zombSpawn_"..CurTime(), 1, 1,
  2.                 Spawnzomb( pl, pl:GetPos(), pl:GetAngles() )
  3.         )

Also, just want to make sure you know that one of the "1"s you have in the parameter list there means that it's delaying the function call for a second.
Experiencing God's grace one day at a time.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Need some help with a ULX LUA command.
« Reply #33 on: June 26, 2011, 10:39:09 am »
Oo.. Good point.. you are trying to spactate an entity that doesn't exist. I should have caught that.

1 second.

Use this code.. Replace your whole code with this...

Code: Lua
  1. function Spawnzomb( pl, pos, ang )     
  2.         R = { "npc_fastzombie", "npc_zombie", "npc_zombie_torso", "npc_zombine", "npc_fastzombie_torso" }
  3.  
  4.         pl.zomb = ents.Create( R[math.random(1,5)] )
  5.         pl.zomb:SetAngles( ang )
  6.         pl.zomb:SetPos( pos )
  7.         pl.zomb:Spawn()
  8.         pl.zomb:Activate()
  9.         pl:Spectate( OBS_MODE_CHASE )
  10.         pl:SpectateEntity( pl.zomb )
  11.         timer.Create( "zombRemove_"..CurTime(), 120.5, 1, DespawnZomb, pl, pl.zomb )
  12.  
  13. end
  14.  
  15. function DespawnZomb( pl, zomb )
  16.        
  17.         if zomb then
  18.                 zomb:Remove()
  19.         end
  20.         pl:UnSpectate()
  21.         pl:Freeze( false )
  22.         pl:Spawn()
  23.        
  24. end
  25.  
  26. function ulx.zombify( calling_ply, target_ply )
  27.  
  28.         local pl = target_ply
  29.         local pos = pl:GetPos()
  30.         local ang = pl:GetAngles()
  31.         pl:EmitSound( "ambient/creatures/town_zombie_call1.wav", 100, 100 )    
  32.         pl:StripWeapons()
  33.         Spawnzomb( pl, pos, ang )
  34.  
  35.         ulx.fancyLogAdmin( calling_ply, "#A zombified #T for a #s amount of time", command, target_ply )
  36. end
  37. local zombify = ulx.command( "Fun", "ulx zombify", ulx.zombify, "!zombify" )
  38. zombify:addParam{ type=ULib.cmds.PlayerArg }
  39. zombify:defaultAccess( ULib.ACCESS_SUPERADMIN )
  40. zombify:help( "Turn a player into a zombie. Note: This can only be used on a single player." )
  41.  

What I did was move some things around. I removed the timer you had to spawn the zombie as it was causing an issue with your spawn function telling the player to spectate an entity that didn't exist for another 1 second. I also placed some of the player control elements into the same function as the one spawning the zombie. This code should work now... (albeit untested)
« Last Edit: June 26, 2011, 12:38:44 pm by MrPresident »

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #34 on: June 26, 2011, 06:35:08 pm »
Oo.. Good point.. you are trying to spactate an entity that doesn't exist. I should have caught that.

1 second.

Use this code.. Replace your whole code with this...

Code: Lua
  1. function Spawnzomb( pl, pos, ang )     
  2.         R = { "npc_fastzombie", "npc_zombie", "npc_zombie_torso", "npc_zombine", "npc_fastzombie_torso" }
  3.  
  4.         pl.zomb = ents.Create( R[math.random(1,5)] )
  5.         pl.zomb:SetAngles( ang )
  6.         pl.zomb:SetPos( pos )
  7.         pl.zomb:Spawn()
  8.         pl.zomb:Activate()
  9.         pl:Spectate( OBS_MODE_CHASE )
  10.         pl:SpectateEntity( pl.zomb )
  11.         timer.Create( "zombRemove_"..CurTime(), 120.5, 1, DespawnZomb, pl, pl.zomb )
  12.  
  13. end
  14.  
  15. function DespawnZomb( pl, zomb )
  16.        
  17.         if zomb then
  18.                 zomb:Remove()
  19.         end
  20.         pl:UnSpectate()
  21.         pl:Freeze( false )
  22.         pl:Spawn()
  23.        
  24. end
  25.  
  26. function ulx.zombify( calling_ply, target_ply )
  27.  
  28.         local pl = target_ply
  29.         local pos = pl:GetPos()
  30.         local ang = pl:GetAngles()
  31.         pl:EmitSound( "ambient/creatures/town_zombie_call1.wav", 100, 100 )    
  32.         pl:StripWeapons()
  33.         Spawnzomb( pl, pos, ang )
  34.  
  35.         ulx.fancyLogAdmin( calling_ply, "#A zombified #T for a #s amount of time", command, target_ply )
  36. end
  37. local zombify = ulx.command( "Fun", "ulx zombify", ulx.zombify, "!zombify" )
  38. zombify:addParam{ type=ULib.cmds.PlayerArg }
  39. zombify:defaultAccess( ULib.ACCESS_SUPERADMIN )
  40. zombify:help( "Turn a player into a zombie. Note: This can only be used on a single player." )
  41.  

What I did was move some things around. I removed the timer you had to spawn the zombie as it was causing an issue with your spawn function telling the player to spectate an entity that didn't exist for another 1 second. I also placed some of the player control elements into the same function as the one spawning the zombie. This code should work now... (albeit untested)

I see so if I want a one second delay I would have to delay both of them, so it looks for an entity that is available. Well now to test it and once I am done with that, to start changing the code to add an effect before the zombie spawns.

Edit: Thank you very much, and I dont know if this is allowed but I have converted some evolve commands to ULX and I was surprised that you dont have the arm,give, and spawn commands. The commands I converted are as follows give,arm,spawn,trainf***. Again thanks for your help I am going to test it now and come back with the results.

Misc: Why would unattended children be given a shot of espresso and a free puppy?
« Last Edit: June 26, 2011, 06:42:04 pm by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Need some help with a ULX LUA command.
« Reply #35 on: June 26, 2011, 08:24:07 pm »
What do those commands do?
(No need for explanation of the TF command. IMO, our "maul" was much better for punishments like that)

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #36 on: June 26, 2011, 11:51:40 pm »
What do those commands do?
(No need for explanation of the TF command. IMO, our "maul" was much better for punishments like that)

give: Gives a specified weapon to a specified player.
arm: The opposite of strip.
spawn: Re-spawns a player.

Edit: I may be converting ABAH in the future so yea.

Back On Topic: Still did not test the zombify command.  :(  . Hope the server owner lets me test it tomorrow, I just co-own. Should I add pl.zomb:SetNPCState( 3 )?
« Last Edit: June 27, 2011, 12:51:33 am by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #37 on: June 27, 2011, 01:05:30 am »
Ok, changed the code and I am going to test it now.

Code: [Select]
-- ULX Zombify for ULX SVN/ULib SVN by HeLLFox_15 with assistance from MrPresident, Megiddo, and JamminR
-- Organized by MrPresident
function Spawnzomb( pl, pos, ang, command )
R = { "npc_fastzombie", "npc_zombie", "npc_zombie_torso", "npc_zombine", "npc_fastzombie_torso" }

pl.zomb = ents.Create( R[math.random(1,5)] )
pl.zomb:SetAngles( ang )
pl.zomb:SetPos( pos )
pl.zomb:Spawn()
pl.zomb:Activate()
pl.zomb:SetNPCState(3)
pl:Spectate( OBS_MODE_CHASE )
pl:SpectateEntity( pl.zomb )
timer.Create( "zombRemove_"..CurTime(), command, 1, DespawnZomb, pl, pl.zomb )

end

function DespawnZomb( pl, zomb )

if zomb then
zomb:Remove()
end
pl:UnSpectate()
pl:Freeze( false )
pl:Spawn()

end

function ulx.zombify( calling_ply, target_ply )

local pl = target_ply
local pos = pl:GetPos()
local ang = pl:GetAngles()
local Effect = EffectData()
Effect:SetOrigin(pos)
Effect:SetStart(pos)
Effect:SetMagnitude(512)
Effect:SetScale(128)
util.Effect("cball_explode", Effect)

pl:EmitSound( "ambient/creatures/town_zombie_call1.wav", 100, 100 )
pl:StripWeapons()
Spawnzomb( pl, pos, ang, own )

ulx.fancyLogAdmin( calling_ply, "#A zombified #T for #s seconds", target_ply, command )
end
local zombify = ulx.command( "Fun", "ulx zombify", ulx.zombify, "!zombify" )
zombify:addParam{ type=ULib.cmds.PlayerArg }
zombify:addParam{ type=ULib.cmds.NumArg, hint="command", min=10, max=60, default=10, ULib.cmds.optional }
zombify:defaultAccess( ULib.ACCESS_SUPERADMIN )
zombify:help( "Turn a single player into a zombie." )

Please notice...

   local Effect = EffectData()
   Effect:SetOrigin(pos)
   Effect:SetStart(pos)
   Effect:SetMagnitude(512)
   Effect:SetScale(128)
   util.Effect("cball_explode", Effect)
« Last Edit: June 27, 2011, 08:16:17 pm by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #38 on: June 27, 2011, 08:16:47 pm »
This script works, but I am missing one more part, how would I make the zombie kill-able and if the zombie dies the player re-spawns.
I have discovered that I can not specify the time that the player is zombified for. How ever it all seems correct and I am not getting an error exept when I run the command it says "HeLLFox_15 zombified Bot01 for (null) seconds"
I cry every time I see that I am not a respected member of this community.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Need some help with a ULX LUA command.
« Reply #39 on: June 28, 2011, 04:15:00 am »
You need to add "command" to the function parameter list.

As far as how to make the player respawn when the zombie is killed, there's a callback on entity destroyed function somewhere. Maybe in the ents library? Or on the ent directly? Anyways, you can find it on the gmod wiki.
Experiencing God's grace one day at a time.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #40 on: June 29, 2011, 08:20:11 pm »
You need to add "command" to the function parameter list.

As far as how to make the player respawn when the zombie is killed, there's a callback on entity destroyed function somewhere. Maybe in the ents library? Or on the ent directly? Anyways, you can find it on the gmod wiki.

Ah I see I overlooked the actual command because I put it in the first function. Now I feel stupid :P.
I cry every time I see that I am not a respected member of this community.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #41 on: July 04, 2011, 08:16:06 am »
I am going to test my new code and see if it works, if you see any problems or ways that I can "optimize" please tell me.

Code: [Select]
-- ULX Zombify for ULX SVN/ULib SVN by HeLLFox_15 with assistance from MrPresident, Megiddo, and JamminR
-- Organized by MrPresident
function Spawnzomb( pl, pos, ang, command )
R = { "npc_fastzombie", "npc_zombie", "npc_zombie_torso", "npc_zombine", "npc_fastzombie_torso" }

pl.zomb = ents.Create( R[math.random(1,5)] )
pl.zomb:SetAngles( ang )
pl.zomb:SetPos( pos )
pl.zomb:Spawn()
pl.zomb:Activate()
pl.zomb:SetNPCState(3)
pl:Spectate( OBS_MODE_CHASE )
pl:SpectateEntity( pl.zomb )
if( pl.zomb:Alive() ) then else DespawnZomb() end
timer.Create( "zombRemove_"..CurTime(), command, 1, DespawnZomb, pl, pl.zomb )

end

function DespawnZomb( pl, zomb )

if zomb then
zomb:Remove()
end
pl:UnSpectate()
pl:Freeze( false )
pl:Spawn()

end

function ulx.zombify( calling_ply, target_ply, command )

local pl = target_ply
local pos = pl:GetPos()
local ang = pl:GetAngles()
local Effect = EffectData()
Effect:SetOrigin(pos)
Effect:SetStart(pos)
Effect:SetMagnitude(512)
Effect:SetScale(128)
util.Effect("cball_explode", Effect)

pl:EmitSound( "ambient/creatures/town_zombie_call1.wav", 100, 100 )
pl:StripWeapons()
Spawnzomb( pl, pos, ang, own )

ulx.fancyLogAdmin( calling_ply, "#A zombified #T for #s seconds", target_ply, command )
end
local zombify = ulx.command( "Fun", "ulx zombify", ulx.zombify, "!zombify" )
zombify:addParam{ type=ULib.cmds.PlayerArg }
zombify:addParam{ type=ULib.cmds.NumArg, hint="command", min=10, max=60, default=10, ULib.cmds.optional }
zombify:defaultAccess( ULib.ACCESS_SUPERADMIN )
zombify:help( "Turn a single player into a zombie." )

I would also like to know on how I would make the player spectate the zombies head, not its feet.
I cry every time I see that I am not a respected member of this community.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Need some help with a ULX LUA command.
« Reply #42 on: July 04, 2011, 10:08:05 am »
if you see any problems

1) I recommend making the hint more clear in the command object addparm. hint="command" doesn't tell me what it does if I were to type the zombify command incorrectly. That hint sets up a portion of the error message in ULX if I do type it incorrectly.
You don't have to rename the variable (though that wouldn't hurt), but the hint string would help someone like me not familiar know what the parameter does.
2) You 'lose' the actual variable after calling it. Though it gets passed when you call the zombie function, you then lose it in Spawnzombie (looks like 'own' should be 'command').

EDIT - Sorry, forgot where i was going with this part.
I would also like to know on how I would make the player spectate the zombies head, not its feet.

I'm not 100% sure. However, our ulx.spectate function uses a different Spectate() function than your OBS_MODE_CHASE.
You want to check out Player.Spectate .
It actually mentions the one we use, and mentions a tip about weapons. (THough I personally don't recommend stripping, unless you also use ULX's functions for remembering what player had before being changed.
See the ulx spectate command in lua\ulx\sh\util.lua
« Last Edit: July 04, 2011, 08:40:35 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #43 on: July 06, 2011, 02:54:52 am »
Ok I will change it to OBS_MODE_IN_EYE. Also I noticed that ulx.fancyLogAdmin is not displaying a message after I use the command.

Code: [Select]
-- ULX Zombify for ULX SVN/ULib SVN by HeLLFox_15 with assistance from MrPresident, Megiddo, and JamminR
-- Organized by MrPresident
function Spawnzomb( pl, pos, ang, number )
R = { "npc_fastzombie", "npc_zombie", "npc_zombie_torso", "npc_zombine", "npc_fastzombie_torso" }

pl.zomb = ents.Create( R[math.random(1,5)] )
pl.zomb:SetAngles( ang )
pl.zomb:SetPos( pos )
pl.zomb:Spawn()
pl.zomb:Activate()
pl.zomb:SetNPCState(3)
pl.zomb:CallOnRemove( DespawnZomb, pl, pl.zomb)
pl:Spectate( OBS_MODE_IN_EYE )
pl:SpectateEntity( pl.zomb )
if( pl.zomb:Alive() ) then else DespawnZomb( pl, pl.zomb ) end
timer.Create( "zombRemove_"..CurTime(), number, 1, DespawnZomb, pl, pl.zomb )

end

function DespawnZomb( pl, zomb )

if zomb then
zomb:Remove()
end
pl:UnSpectate()
pl:Freeze( false )
pl:Spawn()

end

function ulx.zombify( calling_ply, target_ply, number )

local pl = target_ply
local pos = pl:GetPos()
local ang = pl:GetAngles()
local Effect = EffectData()
Effect:SetOrigin(pos)
Effect:SetStart(pos)
Effect:SetMagnitude(512)
Effect:SetScale(128)
util.Effect("cball_explode", Effect)

pl:EmitSound( "ambient/creatures/town_zombie_call1.wav", 100, 100 )
pl:StripWeapons()
Spawnzomb( pl, pos, ang, own )

ulx.fancyLogAdmin( calling_ply, "#A zombified #T for #s seconds", target_ply, number )
end
local zombify = ulx.number( "Fun", "ulx zombify", ulx.zombify, "!zombify" )
zombify:addParam{ type=ULib.cmds.PlayerArg }
zombify:addParam{ type=ULib.cmds.NumArg, hint="number", min=10, max=60, default=10, ULib.cmds.optional }
zombify:defaultAccess( ULib.ACCESS_SUPERADMIN )
zombify:help( "Turn a single player into a zombie." )

Edit: As you may have seen in one of my other posts, my command gets no. Errors but that was B4 this update. So after I test this I will get back to you.

Edit Read: Also what do you mean by "looks like 'own' should be 'command'", do you mean that if I change the hint to 'own' but not the variable that's how it would run?
« Last Edit: July 06, 2011, 02:59:50 am by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Need some help with a ULX LUA command.
« Reply #44 on: July 06, 2011, 02:34:41 pm »
Ok I will change it to OBS_MODE_IN_EYE.
Worth a shot.

ulx.fancyLogAdmin is not displaying a message after I use the command.

Sorry, I just looked over the actual function and, well, it would take me longer to research all it does than it would for Megiddo to tell you whats wrong.
It's got some cool checks in it, I can tell you that much. Some I don't even understand. :D

hint to 'own' but not the variable that's how it would run?

No no no no. :D
In the code I was originally commenting on.
Hint. It's just that. It's not a variable. It's a string. It tells anyone that types the command incorrectly what is expected.
Like if I typed "ulx zombify fred forever" it would come back and say something similar to "Command parameters incorrect - ulx zombify <player> <your_hint string, default 10>
I recommend "seconds" or "time in seconds"

As for own vs command variables -
You broke the code by changing it to ulx.number("fun..blah blah). It has to be ulx.command.. that's what tells ULX you're setting up stuff.
Your ulx.command object passes 3 variables to your ulx.zombify, (not visible) who called it, addparam - target, addparm - time)

Those three fill in the following when you call the function.
function ulx.zombify( calling_ply, target_ply, number )
However...not once during the rest of the function, all the way to the 'end' statement, do you ever use that 3rd variable, now named number, originally named 'command' when I commented on it.
Then, right before the end statement, you call another function -
Spawnzomb( pl, pos, ang, own )
Where in any of the lines from function ulx zombify to the end statement after that call does "own" come into play?
You're passing a nil value to spawnzomb on that final variable.
If it's working in any way for you, I'd be surprised how.

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print