General > Developers Corner

Need some help with a ULX LUA command.

<< < (13/14) > >>

Megiddo:
Try it out and see if it works or not. :)

LuaTenshi:
Now it says the following...


--- Code: ---[addons\ulx_sv-hellfox_15\lua\ulx\modules\sh\sh_zombify.lua:15] attempt to call method 'Alive' <a nil value>
--- End code ---

Edit: apparently 'Alive()' only works on players, what would I use to get if the zombie is alive or not?

I am going to try to use Entity:health() instead.

MrPresident:
I think when an entity is killed or removed its entity is removed. So a simple if Entity then should work.


or Entity:IsValid()

LuaTenshi:
[OLD](May-be) You may think this is odd but when I use my command on a player, they lose the ability to move and ULX does not recognize them as being in the server. They also lose any ranks they had on the server.
------------

My new code...


--- Code: ----- 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, ztime )
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_DEATHCAM )
pl:SpectateEntity( pl.zomb )
if not ( pl.zomb ) then DespawnZomb( pl, pl.zomb, pos ) end
if ( pl.zomb ) then
timer.Create( "zombRemove_"..CurTime(), ztime, 1, DespawnZomb, pl, pl.zomb, pos )
end

end

function DespawnZomb( pl, zomb, pos )

if ( zomb and zomb:IsValid() ) then
pl:UnSpectate()
zomb:Remove()
end 
pl:Spawn()
pl:SetPos( pos )

end

function ulx.zombify( calling_ply, target_ply, ztime )

for _,pl in pairs( target_ply ) do
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, ztime )
end
ulx.fancyLogAdmin( calling_ply, "#A zombified #T for #s seconds", target_ply, ztime )
end
local zombify = ulx.command( "Fun", "ulx zombify", ulx.zombify, "!zombify" )
zombify:addParam{ type=ULib.cmds.PlayersArg }
zombify:addParam{ type=ULib.cmds.NumArg, hint="ztime", min=10, max=60, default=10, ULib.cmds.optional }
zombify:defaultAccess( ULib.ACCESS_SUPERADMIN )
zombify:help( "Turn a players into zombies." )

--- End code ---

It seems to work...


--- Code: ---L 07/26/2011 - 07:01:03: Log file started (file "logs\L0726000.log") (game "C:\srcds\orangebox\garrysmod") (version "4616")
L 07/26/2011 - 07:01:28: "Bot01<2><BOT><>" connected, address "none"
L 07/26/2011 - 07:01:28: "Bot01<2><BOT><>" entered the game
L 07/26/2011 - 07:01:29: server_cvar: "sv_tags" "alltalk,garrysmod125,gm:sandbox,gravhull,scriptenforcer,wiresvn2463"
L 07/26/2011 - 07:02:02: [ULX] (Console) zombified Bot01 for 10 seconds
L 07/26/2011 - 07:06:14: Log file closed

--- End code ---

How ever I would like a ulx.fancyLogAdmin() to tell every one that the player you ran it on has been "unzombified".

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given

[0] Board index

Go to full version