General > Developers Corner

Need some help with a ULX LUA command.

(1/14) > >>

LuaTenshi:
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: ----- 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." )

--- End code ---

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>

Megiddo:
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.

LuaTenshi:

--- Quote from: Megiddo 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.

--- End quote ---

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>"

Megiddo:
Let's tackle the first error. Arrays in Lua are 1-indexed, so you want math.random(1,5) (you also counted too high).

LuaTenshi:

--- Quote from: Megiddo 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).

--- End quote ---

Ok fixed that. Also just to avoid clutter is it not better to do 2 at a time?

Navigation

[0] Message Index

[#] Next page

Go to full version