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