• 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 #15 on: June 23, 2011, 06:34:45 pm »
Cool, let me know how it runs.

I was only going to pick it up if you gave up on it. The idea is too good to let it just die, though I'd rather have you be the one to complete and release it seeing as it was your idea.

Oh OK, so I tested it in the server how it is currently and nothing happens, I mean the command does not run and gives no errors.

Edit: I think I know what the problem is...

in places such as...

Code: [Select]
function Spawnzomb( Pos, Ang, pl, pl.zomb )
and

Code: [Select]
function ulx.zombify( calling_ply, target_plys, pl.zomb )
pl.zomb should probably just be "zomb". I am gonna try that and hopefully get some thing from it.
« Last Edit: June 23, 2011, 06:38:33 pm by HeLLFox_15 »
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 #16 on: June 23, 2011, 07:16:36 pm »
No, pl.zomb is the entity now.. as long as the function identifies pl as the player entity it should see it.


zomb will never equal pl.zomb... if you know how OOP works you will know why.

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 #17 on: June 23, 2011, 08:34:38 pm »
Can't speak for other visitors, but MrP, my team mates, and a few other regulars here are more than happy to assist, give credit when credit is due, and like seeing new insight and ideas from others such as yourself, even if learning Glua for the first time (Most of us learn here, even when those such as yourself ask questions about stuff we've seen, there's always something we haven't.) :D
If you take a look at the ULib and ULX change logs, you'll see various honorable mentions of users who have helped us over time, including MrPresident himself.
"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 #18 on: June 24, 2011, 08:28:47 am »
I now have an error the error is...

Code: [Select]
[addons\ulx_svn-hellfox_15\lua\ulx\modules\sh\sh_zombify.lua:3] ')' expected near '.'
« Last Edit: June 24, 2011, 08:54:35 am by HeLLFox_15 »
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 #19 on: June 24, 2011, 08:56:01 am »
I now have an error the error is...

Code: [Select]
[addons\ulx_svn-hellfox_15\lua\ulx\modules\sh\sh_zombify.lua:3] ')' expected near '.'

Could you share line three and a few of the surrounding lines? Line 3 on the OP is a blank line.
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 #20 on: June 24, 2011, 09:05:54 am »
Could you share line three and a few of the surrounding lines? Line 3 on the OP is a blank line.

Well scence I added that comment into the lua... "function Spawnzomb( Pos, Ang, pl, pl.zomb )" is in line 3.

Code: [Select]
-- ULX Zombify for ULX SVN/ULib SVN by HeLLFox_15 with assistance from MrPresident, Megiddo, and JamminR

function Spawnzomb( Pos, Ang, pl, pl.zomb )
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()
timer.Create( "zombRemoveB_"..CurTime(), 120.5, 1, function( pl.zomb, target_plys ) pl.zomb:Remove() end )

end

function ulx.zombify( calling_ply, target_plys, pl.zomb )
for _, pl in ipairs( target_plys, calling_ply ) do
pl:SetMoveType( MOVETYPE_NONE )
pl:EmitSound( "ambient/creatures/town_zombie_call1.wav", 100, 100 )

timer.Create( "zombSpawn_"..CurTime(), 1, 1, Spawnzomb( pl:GetPos(), pl:GetAngles(), pl ) )
pl:StripWeapons()
pl:Spectate( OBS_MODE_CHASE )
pl:SpectateEntity( pl.zomb )

timer.Create( "zombRemoveA_"..CurTime(), 120, 1,
function( target_plys )
pl:UnSpectate()
pl:Freeze( false )
pl:Spawn()
end )

end

ulx.fancyLogAdmin( calling_ply, "#A zombified #T for a #s amount of time", command, target_plys )
end

local zombify = ulx.command( "Fun", "ulx zombify", ulx.zombify, "!zombify" )
zombify:addParam{ type=ULib.cmds.PlayerArg }
zombify:defaultAccess( ULib.ACCESS_SUPERADMIN )
zombify:help( "Turn a player into a zombie. Note: Do not use this on multiple players." )
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 #21 on: June 24, 2011, 11:58:29 am »
in your function line pl hasn't technically been defined as the player entity yet. So pl.zomb is throwing that error. I don't see why you are passing pl.zomb as a 4th argument in the first place. You never use it.

Just remove that part of the function and it should not error on you.

change
Code: Lua
  1. function Spawnzomb( Pos, Ang, pl, pl.zomb )
  2.  

to

Code: Lua
  1. function Spawnzomb( Pos, Ang, pl )
  2.  
« Last Edit: June 25, 2011, 12:51:13 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 #22 on: June 24, 2011, 04:36:13 pm »
I updated my code once again and removed the pl.zomb from the functions. Now I am getting this error...

Code: [Select]
[@addons\ulx_svn-hellfox_15\lua\ulx\modules\sh\sh_zombify.lua:16] bad argument #1 to 'ipairs' (table expected, got Player)
Edit: I changed the code in my opening topic code, to what I have now.
« Last Edit: June 24, 2011, 04:38:15 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 #23 on: June 24, 2011, 08:54:04 pm »
Looks like you're trying to change the function to accept multiple player objects?
The ULX command object structure you're using only sends a single player target object.
Also, ipairs is for an "I"ndexed table.
1) The player object isn't indexed.
2) And, though I'd have trouble truly explaining (as I don't always 100% fully see it myself), the player object isn't 100% a table that you can even use 'pairs' on (though, it can have table-like (.zomb) things tied to it.

Hope that at least gets you pointed a bit further.
"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 #24 on: June 24, 2011, 09:06:55 pm »
Looks like you're trying to change the function to accept multiple player objects?
The ULX command object structure you're using only sends a single player target object.
Also, ipairs is for an "I"ndexed table.
1) The player object isn't indexed.
2) And, though I'd have trouble truly explaining (as I don't always 100% fully see it myself), the player object isn't 100% a table that you can even use 'pairs' on (though, it can have table-like (.zomb) things tied to it.

Hope that at least gets you pointed a bit further.

So to make it a table I would have to put... pl = {} or pl {} or some thing like that
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 #25 on: June 25, 2011, 07:01:47 am »
Pretty sure that wouldn't work. My more advanced fellow coders around here coiuld provide more.
But, as of when I posted, you're passing the function a single player object at target.
Not a table of players. Though the object holds more about the player kind of like a table..it's not a table the way we're used to.
Also, you're using Ipairs, i is for indexed...that table wouldn't be indexed. You'd want pairs, if you could use either one in that case.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Need some help with a ULX LUA command.
« Reply #26 on: June 25, 2011, 01:11:00 pm »
Give this a try... I redid a little bit of the code for you. you had a lot of stuff in there that was unnecessary. I also broke it into 3 functions. Rather than doing all of the removing and respawning the player in timers I added a function that would take care of all of it and used that instead.

This is untested, but I think it SHOULD work. Let me know if there are any errors.


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.         timer.Create( "zombRemove_"..CurTime(), 120.5, 1, DespawnZomb( pl ) )
  10.  
  11. end
  12.  
  13. function DespawnZomb( pl )
  14.        
  15.         if pl.zomb then
  16.                 pl.zomb:Remove()
  17.         end
  18.         pl:UnSpectate()
  19.         pl:Freeze( false )
  20.         pl:Spawn()
  21.        
  22. end
  23.  
  24. function ulx.zombify( calling_ply, target_ply )
  25.  
  26.         local pl = target_ply
  27.         pl:EmitSound( "ambient/creatures/town_zombie_call1.wav", 100, 100 )    
  28.        
  29.         timer.Create( "zombSpawn_"..CurTime(), 1, 1,
  30.                 Spawnzomb( pl, pl:GetPos(), pl:GetAngles() )
  31.         )
  32.         pl:StripWeapons()
  33.         pl:Spectate( OBS_MODE_CHASE )
  34.         pl:SpectateEntity( pl.zomb )
  35.        
  36.         ulx.fancyLogAdmin( calling_ply, "#A zombified #T for a #s amount of time", command, target_ply )
  37. end
  38. local zombify = ulx.command( "Fun", "ulx zombify", ulx.zombify, "!zombify" )
  39. zombify:addParam{ type=ULib.cmds.PlayerArg }
  40. zombify:defaultAccess( ULib.ACCESS_SUPERADMIN )
  41. zombify:help( "Turn a player into a zombie. Note: This can only be used on a single player." )
  42.  

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 #27 on: June 25, 2011, 02:41:31 pm »
Hellfox, can you understand what MrPresident has done? Follow the logic, etc?
Also,  just cause I like tidy help when available, if I were doing it, I'd change "Turn a player into a zombie. Note: This can only be used on a single player." to
"Turn a (*single!) player into a zombie." or something like that. Any attempt to use multiple players would error message on its own our default "can't use multiple targets" message. :)
Though, thats just me and my oddness about some things.
"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 #28 on: June 25, 2011, 05:36:16 pm »
Give this a try... I redid a little bit of the code for you. you had a lot of stuff in there that was unnecessary. I also broke it into 3 functions. Rather than doing all of the removing and respawning the player in timers I added a function that would take care of all of it and used that instead.

This is untested, but I think it SHOULD work. Let me know if there are any errors.


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.         timer.Create( "zombRemove_"..CurTime(), 120.5, 1, DespawnZomb( pl ) )
  10.  
  11. end
  12.  
  13. function DespawnZomb( pl )
  14.        
  15.         if pl.zomb then
  16.                 pl.zomb:Remove()
  17.         end
  18.         pl:UnSpectate()
  19.         pl:Freeze( false )
  20.         pl:Spawn()
  21.        
  22. end
  23.  
  24. function ulx.zombify( calling_ply, target_ply )
  25.  
  26.         local pl = target_ply
  27.         pl:EmitSound( "ambient/creatures/town_zombie_call1.wav", 100, 100 )    
  28.        
  29.         timer.Create( "zombSpawn_"..CurTime(), 1, 1,
  30.                 Spawnzomb( pl, pl:GetPos(), pl:GetAngles() )
  31.         )
  32.         pl:StripWeapons()
  33.         pl:Spectate( OBS_MODE_CHASE )
  34.         pl:SpectateEntity( pl.zomb )
  35.        
  36.         ulx.fancyLogAdmin( calling_ply, "#A zombified #T for a #s amount of time", command, target_ply )
  37. end
  38. local zombify = ulx.command( "Fun", "ulx zombify", ulx.zombify, "!zombify" )
  39. zombify:addParam{ type=ULib.cmds.PlayerArg }
  40. zombify:defaultAccess( ULib.ACCESS_SUPERADMIN )
  41. zombify:help( "Turn a player into a zombie. Note: This can only be used on a single player." )
  42.  

K, science Gmod just came up I wont be able to give it a try to day but I will test it out tomorrow. I see that you also reordered it a little, so in that order you have

1. spawn the zomb entity
2. remove and undo effects on the player
3. apply effects onto the player and call zomb spawn.

so when it runs it should use this order 3,1,2

Edit: in response to JamminR. Yes I understand it, and K I will change it in the release, I am also going to see if I can add a nice effect to when the player disappears and the zombie spawns.
« Last Edit: June 25, 2011, 05:38:48 pm by HeLLFox_15 »
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 #29 on: June 25, 2011, 05:39:47 pm »
I suppose that is the order that the functions would be run. However, in lua all of the functions are loaded into memory simultaneously so the order doesn't really matter. All that needs to be done is for you to use the ulx command and the rest will be taken care of automatically.

  • Print