General > Developers Corner

Need some help with a ULX LUA command.

<< < (12/14) > >>

LuaTenshi:

--- Quote from: JamminR on July 15, 2011, 01:59:47 PM ---You're trying to get a position on a table of players, even if you only specify one.
Your ULX command setup uses cmds.PlayersArg - plural, which passes a table of player objects. It allows for multiple targets, but you have to loop through that table to get them even if it's only one.

--- End quote ---

So I should do some thing like this...


--- Code: ---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)
end

--- End code ---

Megiddo:

--- Quote from: HeLLFox_15 on July 15, 2011, 06:23:25 PM ---So I should do some thing like this...


--- Code: ---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)
end

--- End code ---

--- End quote ---

What happens when you use that code?

LuaTenshi:
I am now using this 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.zomb:CallOnRemove( DespawnZomb, pl, pl.zomb)
pl:Spectate( OBS_MODE_IN_EYE )
pl:SpectateEntity( pl.zomb )
if not ( pl.zomb ) then DespawnZomb( pl, pl.zomb ) end
if ( pl.zomb ) then
timer.Create( "zombRemove_"..CurTime(), ztime, 1, DespawnZomb, pl, pl.zomb )
end

end

function DespawnZomb( pl, zomb )

if zomb then
zomb:Remove()
end
pl:UnSpectate()
pl:Freeze( false )
pl:Spawn()

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

(You can see that I have made changes to get if the zombie is alive or not, and that I have added a for loop.)

...and I am now getting yet another error (This one made me LOL)...


--- Code: ---*******************************************************
Error calling die function: 02647B38 for entity [NPC 316/npc_zombine]
ERROR: attempt to call userdata value
*******************************************************

--- End code ---

And if you where foundering why I was gone for so long it was because I was coding for an RP server. I guess posting here helped me get recognized.

Note: Would any of you like to add me on steam?

Megiddo:
You're not using CallOnRemove correctly.

LuaTenshi:
So would I use some thing like this...


--- Code: ---pl.zomb:CallOnRemove( "Spawnply", DespawnZomb, pl, pl.zomb)
--- End code ---

Because as the wiki demonstrated it should go...

Entity:CallOnRemove( String, Function, Arguments )

If I have multiple arguments would they have to be in brackets?

Edit: I am new to CallOnRemove :P

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version