General > Developers Corner

Need some help with a ULX LUA command.

<< < (9/14) > >>

LuaTenshi:

--- Quote from: Megiddo on June 28, 2011, 04:15:00 AM ---You need to add "command" to the function parameter list.

As far as how to make the player respawn when the zombie is killed, there's a callback on entity destroyed function somewhere. Maybe in the ents library? Or on the ent directly? Anyways, you can find it on the gmod wiki.

--- End quote ---

Ah I see I overlooked the actual command because I put it in the first function. Now I feel stupid :P.

LuaTenshi:
I am going to test my new code and see if it works, if you see any problems or ways that I can "optimize" please tell me.


--- 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, command )
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_CHASE )
pl:SpectateEntity( pl.zomb )
if( pl.zomb:Alive() ) then else DespawnZomb() end
timer.Create( "zombRemove_"..CurTime(), command, 1, DespawnZomb, pl, pl.zomb )

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, command )

local pl = target_ply
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, own )

ulx.fancyLogAdmin( calling_ply, "#A zombified #T for #s seconds", target_ply, command )
end
local zombify = ulx.command( "Fun", "ulx zombify", ulx.zombify, "!zombify" )
zombify:addParam{ type=ULib.cmds.PlayerArg }
zombify:addParam{ type=ULib.cmds.NumArg, hint="command", min=10, max=60, default=10, ULib.cmds.optional }
zombify:defaultAccess( ULib.ACCESS_SUPERADMIN )
zombify:help( "Turn a single player into a zombie." )

--- End code ---

I would also like to know on how I would make the player spectate the zombies head, not its feet.

JamminR:

--- Quote from: HeLLFox_15 on July 04, 2011, 08:16:06 AM ---if you see any problems

--- End quote ---

1) I recommend making the hint more clear in the command object addparm. hint="command" doesn't tell me what it does if I were to type the zombify command incorrectly. That hint sets up a portion of the error message in ULX if I do type it incorrectly.
You don't have to rename the variable (though that wouldn't hurt), but the hint string would help someone like me not familiar know what the parameter does.
2) You 'lose' the actual variable after calling it. Though it gets passed when you call the zombie function, you then lose it in Spawnzombie (looks like 'own' should be 'command').

EDIT - Sorry, forgot where i was going with this part.

--- Quote from: HeLLFox_15 on July 04, 2011, 08:16:06 AM ---I would also like to know on how I would make the player spectate the zombies head, not its feet.

--- End quote ---

I'm not 100% sure. However, our ulx.spectate function uses a different Spectate() function than your OBS_MODE_CHASE.
You want to check out Player.Spectate .
It actually mentions the one we use, and mentions a tip about weapons. (THough I personally don't recommend stripping, unless you also use ULX's functions for remembering what player had before being changed.
See the ulx spectate command in lua\ulx\sh\util.lua

LuaTenshi:
Ok I will change it to OBS_MODE_IN_EYE. Also I noticed that ulx.fancyLogAdmin is not displaying a message after I use the command.


--- 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, number )
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( pl.zomb:Alive() ) then else DespawnZomb( pl, pl.zomb ) end
timer.Create( "zombRemove_"..CurTime(), number, 1, DespawnZomb, pl, pl.zomb )

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, number )

local pl = target_ply
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, own )

ulx.fancyLogAdmin( calling_ply, "#A zombified #T for #s seconds", target_ply, number )
end
local zombify = ulx.number( "Fun", "ulx zombify", ulx.zombify, "!zombify" )
zombify:addParam{ type=ULib.cmds.PlayerArg }
zombify:addParam{ type=ULib.cmds.NumArg, hint="number", min=10, max=60, default=10, ULib.cmds.optional }
zombify:defaultAccess( ULib.ACCESS_SUPERADMIN )
zombify:help( "Turn a single player into a zombie." )

--- End code ---

Edit: As you may have seen in one of my other posts, my command gets no. Errors but that was B4 this update. So after I test this I will get back to you.

Edit Read: Also what do you mean by "looks like 'own' should be 'command'", do you mean that if I change the hint to 'own' but not the variable that's how it would run?

JamminR:

--- Quote from: HeLLFox_15 on July 06, 2011, 02:54:52 AM ---Ok I will change it to OBS_MODE_IN_EYE.

--- End quote ---
Worth a shot.


--- Quote from: HeLLFox_15 on July 06, 2011, 02:54:52 AM ---ulx.fancyLogAdmin is not displaying a message after I use the command.

--- End quote ---

Sorry, I just looked over the actual function and, well, it would take me longer to research all it does than it would for Megiddo to tell you whats wrong.
It's got some cool checks in it, I can tell you that much. Some I don't even understand. :D


--- Quote from: HeLLFox_15 on July 06, 2011, 02:54:52 AM --- hint to 'own' but not the variable that's how it would run?

--- End quote ---

No no no no. :D
In the code I was originally commenting on.
Hint. It's just that. It's not a variable. It's a string. It tells anyone that types the command incorrectly what is expected.
Like if I typed "ulx zombify fred forever" it would come back and say something similar to "Command parameters incorrect - ulx zombify <player> <your_hint string, default 10>
I recommend "seconds" or "time in seconds"

As for own vs command variables -
You broke the code by changing it to ulx.number("fun..blah blah). It has to be ulx.command.. that's what tells ULX you're setting up stuff.
Your ulx.command object passes 3 variables to your ulx.zombify, (not visible) who called it, addparam - target, addparm - time)

Those three fill in the following when you call the function.
function ulx.zombify( calling_ply, target_ply, number )
However...not once during the rest of the function, all the way to the 'end' statement, do you ever use that 3rd variable, now named number, originally named 'command' when I commented on it.
Then, right before the end statement, you call another function -
Spawnzomb( pl, pos, ang, own )
Where in any of the lines from function ulx zombify to the end statement after that call does "own" come into play?
You're passing a nil value to spawnzomb on that final variable.
If it's working in any way for you, I'd be surprised how.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version