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

0 Members and 2 Guests are viewing this topic.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Need some help with a ULX LUA command.
« on: June 22, 2011, 12:57:27 PM »
I am very new to lua and I need help with a command that I am working on.

I would like to make a lua command that turns a player into a zombie. I could not figure out, how to add effects into this either but those are not really necessary I just want to know what I am doing wrong and what I need to do to get this to work. Please and thank you. I would also like to know on how to make it so that people cant target multiple players with this command.

This is what I have so far.

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

function Spawnzomb( Pos, Ang, pl )
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( target_plys ) pl.zomb:Remove() end )

end

function ulx.zombify( calling_ply, target_plys )
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." )

When I run the script above I get. In the server console.

[@addons\ulx_svn-hellfox_15\ulx\modules\sh\sh_zombify.lua:8] bad argument #1
to 'Create' <string expected. got nil>

When I replace the "pl:SpectateEntity( zomb )" with "pl:SpectateEntity( calling_ply )" to try and avoid the error above.

The player disapears and gets replaced by the zombie, but does not reappear. And I get this error.

Timer Error: atempt to call a nil value
Timer Error: [addons\ulx_svn-hellfox_15\lua\ulx\modules\sh\sh_zombify.lua:13] attempt to index local 'zomb' <a nil value>
« Last Edit: June 24, 2011, 04:37:03 PM 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 #1 on: June 22, 2011, 01:07:45 PM »
We need more information. If the above code doesn't work, what about it doesn't work? Are you getting errors in the client and/or server console during startup or while using the command?

To make it so you can't target multiple players, change ULib.cmds.PlayerArg to ULib.cmds.PlayerArg. Make sure you change your function to accept the single player instead of a table of players as well.
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 #2 on: June 22, 2011, 01:33:19 PM »
We need more information. If the above code doesn't work, what about it doesn't work? Are you getting errors in the client and/or server console during startup or while using the command?

To make it so you can't target multiple players, change ULib.cmds.PlayerArg to ULib.cmds.PlayerArg. Make sure you change your function to accept the single player instead of a table of players as well.

I have also changed my first post...

"When I run the script above I get. In the server console.

[@addons\ulx_svn-hellfox_15\ulx\modules\sh\sh_zombify.lua:8] bad argument #1
to 'Create' <string expected. got nil>

When I replace the "pl:SpectateEntity( zomb )" with "pl:SpectateEntity( calling_ply )" to try and avoid the error above.

The player disapears and gets replaced by the zombie, but does not reappear. And I get this error.

Timer Error: atempt to call a nil value
Timer Error: [addons\ulx_svn-hellfox_15\lua\ulx\modules\sh\sh_zombify.lua:13] attempt to index local 'zomb' <a nil value>"
« Last Edit: June 22, 2011, 01:36:11 PM 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 #3 on: June 22, 2011, 02:00:57 PM »
Let's tackle the first error. Arrays in Lua are 1-indexed, so you want math.random(1,5) (you also counted too high).
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 #4 on: June 22, 2011, 03:18:29 PM »
Let's tackle the first error. Arrays in Lua are 1-indexed, so you want math.random(1,5) (you also counted too high).

Ok fixed that. Also just to avoid clutter is it not better to do 2 at a time?
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 #5 on: June 22, 2011, 03:54:27 PM »
Ok fixed that. Also just to avoid clutter is it not better to do 2 at a time?

From personal experience, I know that trying to take on two errors at once is usually a waste of time because the first one causes the other(s) 95% of the time. Show us the new logs from using the commands now.
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 #6 on: June 22, 2011, 04:29:18 PM »
From personal experience, I know that trying to take on two errors at once is usually a waste of time because the first one causes the other(s) 95% of the time. Show us the new logs from using the commands now.

OK, I fixed the index error. I did not bother testing it through the server because. I now know the error after fiddling around with the code a few times. The main error is that it can not find the entity of the zombie.

When i get a fix for that I will test the code.
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 #7 on: June 22, 2011, 06:37:40 PM »
*bright eyes*
You get this working, and it might be one of the more 'fun' commands to have come out since rocket or explode.
"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: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Need some help with a ULX LUA command.
« Reply #8 on: June 22, 2011, 06:52:09 PM »
You are creating the zombie as a local entity. This can not be called from outside the function it was created in. If the zombie entity is going to be associated with a player and they will only have one at a time, I would recommend anchoring your zombie entity to the player entity. (Ya for OOP)


so instead of zomb you would use ply.zomb. Just make sure you pass the ply entity to the Spawnzomb function.


*Edit* If for some reason you can't get this working.. I would really like to pick it up. Of course I'm not going to steal your idea. ;) Also any help you need on this, let me know.
« Last Edit: June 22, 2011, 06:57:18 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 #9 on: June 22, 2011, 07:07:18 PM »
You are creating the zombie as a local entity. This can not be called from outside the function it was created in. If the zombie entity is going to be associated with a player and they will only have one at a time, I would recommend anchoring your zombie entity to the player entity. (Ya for OOP)


so instead of zomb you would use ply.zomb. Just make sure you pass the ply entity to the Spawnzomb function.


*Edit* If for some reason you can't get this working.. I would really like to pick it up. Of course I'm not going to steal your idea. ;) Also any help you need on this, let me know.

OK, this may seem like a stupid question but would this...
Code: [Select]
timer.Create( "zombSpawn_"..CurTime(), 1, 1, Spawnzomb( pl:GetPos(), pl:GetAngles(), pl ) )...work to pass the players entity to the Spawnzomb command?
I cry every time I see that I am not a respected member of this community.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Need some help with a ULX LUA command.
« Reply #10 on: June 22, 2011, 07:16:20 PM »
Yes, be sure that you change all instances of zomb to pl.zomb though. Also.. it's not a local anymore. You are anchoring it to a global entity.


pl.zomb = ents.Create

not

local zomb = ents.Create


edit: Also.. since you are anchoring it to the players entity.. there is no reason why you can't do this to more than one player at a time. You may want to include some sort of redundancy check though. Maybe check to see if there is already a pl.zomb before creating a new one, and if there is then removing it first.
« Last Edit: June 22, 2011, 07:17:54 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 #11 on: June 22, 2011, 07:36:56 PM »
Yes, be sure that you change all instances of zomb to pl.zomb though. Also.. it's not a local anymore. You are anchoring it to a global entity.


pl.zomb = ents.Create

not

local zomb = ents.Create


edit: Also.. since you are anchoring it to the players entity.. there is no reason why you can't do this to more than one player at a time. You may want to include some sort of redundancy check though. Maybe check to see if there is already a pl.zomb before creating a new one, and if there is then removing it first.

I made the changes to the code. Now all I need to do is test it. By that I mean I need to test it on the Server. So I can get the exact log and errors if there are any.
« Last Edit: June 22, 2011, 07:46:04 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: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Need some help with a ULX LUA command.
« Reply #12 on: June 22, 2011, 07:45:28 PM »
You left them out of the remove timer. You need to fix your zomb variables there as well.

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 #13 on: June 22, 2011, 08:15:14 PM »
You left them out of the remove timer. You need to fix your zomb variables there as well.

I have now replaced each and every occurrence of zomb with pl.zomb, I made sure of that. I will test the script tomorrow. Thank you very much for the help and yes, you can work on it, but I really hope that you give me credit as well.

Note: An effect needs to be added when the zombie replaces the player. (But that's after we get the zombie to actually replace the player.)

Edit: I removed my last one to change the post time. Sorry.
I cry every time I see that I am not a respected member of this community.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Need some help with a ULX LUA command.
« Reply #14 on: June 23, 2011, 05:48:09 AM »
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.