ULX

Author Topic: Need some help with a ULX LUA command.  (Read 30516 times)

0 Members and 5 Guests are viewing this topic.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Need some help with a ULX LUA command.
« Reply #45 on: July 07, 2011, 04:16:07 AM »
The log call looks alright to me. Did you try sticking a print before it to make sure that it's being called? It's suspicious that it wouldn't throw an error if it's having a problem.

Also, your config is set so that you can see echoes, right?
Experiencing God's grace one day at a time.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #46 on: July 07, 2011, 09:06:53 AM »
Worth a shot.
 
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

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.

I did not even notice that "own" was in there, curse you replace all. :P . Your saying if I change "own" to "number" it would work better?

In response to Megiddo. All other commands return with the log, and I left it at default and I believe that default is on correct?
I cry every time I see that I am not a respected member of this community.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Need some help with a ULX LUA command.
« Reply #47 on: July 07, 2011, 11:35:40 AM »
It's on by default
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Need some help with a ULX LUA command.
« Reply #48 on: July 07, 2011, 02:44:12 PM »
Your saying if I change "own" to "number" it would work better?
The chances of it working better are much increased, yes. :)
Coding tip - I recommend naming the variable something easier for you to remember what it is.
You have pl (player), pos (position), ang (angle)... those a pretty good.
if you look at it a year from now, how much time will it take you to figure out/remember what 'number' was.
Now, we all know it's time..but...later...it will take more 'time' to figure out. :) Perhaps ztime (zombie time!)

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #49 on: July 07, 2011, 03:11:04 PM »
The chances of it working better are much increased, yes. :)
Coding tip - I recommend naming the variable something easier for you to remember what it is.
You have pl (player), pos (position), ang (angle)... those a pretty good.
if you look at it a year from now, how much time will it take you to figure out/remember what 'number' was.
Now, we all know it's time..but...later...it will take more 'time' to figure out. :) Perhaps ztime (zombie time!)

ZTime it is then.

Because my post needs to be longer... How would I be able to be part of the Ulysses team? You probably get spammed with that question.

Edit: I am not hijacking my own post. I just wanna know and embarrassed to ask in the chat section. I will come back with an on topic message after I get to test my command.
« Last Edit: July 07, 2011, 03:17:14 PM by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Need some help with a ULX LUA command.
« Reply #50 on: July 07, 2011, 05:07:17 PM »
As far as the Ulysses team, we contact you if we'd like you to join. We'll keep in mind that you're interested.

Not to sound cruel, but if you're looking to be a programmer you'll need a lot more practice (Hey, we all started from nothing!). There's plenty of project ideas floating around to sink your teeth into. I'm almost always willing to help someone who needs help with the ULX/ULib API and sometimes other programming questions... as long as they've made an honest attempt to research the solution on their own first.

If you were looking to contribute to the team some other way, where do you see yourself helping out?

Edit: Also, on the issue of post length: This is a relatively slow forum, as long as your post is contributing to the conversation we don't mind short posts.
Experiencing God's grace one day at a time.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #51 on: July 13, 2011, 11:54:44 PM »
OK, sorry for the delay but it will take some time untill I can test it again.

Code: [Select]
-- 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:Alive() ) then DespawnZomb( pl, pl.zomb ) end
if ( pl.zomb:Alive() ) 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 )

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

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

This is what I have so far I have not tested but please tell me if you see any thing that may be messing it up.
I believe my call on remove function may break it. I also think I should add a timer stop.

ADDITION: I would like to know how I would call data out of UTime like getting how long a player has played on a server.

Edit:

Code: [Select]
[addons\ulx_sv-hellfox_15\lua\ulx\modules\sh\sh_zombify.lua:36] attempt to call method 'GetPos' <a nil value>
« Last Edit: July 14, 2011, 05:38:42 PM by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: Need some help with a ULX LUA command.
« Reply #52 on: July 14, 2011, 10:59:57 AM »
ply:GetUTimeSessionTime()
ply:GetUTimeTotalTime()
I believe.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #53 on: July 15, 2011, 01:34:25 AM »
I have edited my last post specifying the error that I got, I did try to fix this but to no avail. Well guess I will keep trying.
I cry every time I see that I am not a respected member of this community.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Need some help with a ULX LUA command.
« Reply #54 on: July 15, 2011, 01:59:47 PM »
Code: [Select]
[addons\ulx_sv-hellfox_15\lua\ulx\modules\sh\sh_zombify.lua:36] attempt to call method 'GetPos' <a nil value>

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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #55 on: July 15, 2011, 06:23:25 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.

So I should do some thing like this...

Code: [Select]
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
I cry every time I see that I am not a respected member of this community.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Need some help with a ULX LUA command.
« Reply #56 on: July 15, 2011, 07:21:09 PM »
So I should do some thing like this...

Code: [Select]
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

What happens when you use that code?
Experiencing God's grace one day at a time.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #57 on: July 22, 2011, 12:00:20 AM »
I am now using this code...

Code: [Select]
-- 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." )

(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: [Select]
*******************************************************
Error calling die function: 02647B38 for entity [NPC 316/npc_zombine]
ERROR: attempt to call userdata value
*******************************************************

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?
« Last Edit: July 22, 2011, 12:29:43 AM by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Need some help with a ULX LUA command.
« Reply #58 on: July 22, 2011, 04:21:46 AM »
You're not using CallOnRemove correctly.
Experiencing God's grace one day at a time.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need some help with a ULX LUA command.
« Reply #59 on: July 22, 2011, 07:30:43 AM »
So would I use some thing like this...

Code: [Select]
pl.zomb:CallOnRemove( "Spawnply", DespawnZomb, pl, pl.zomb)
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
I cry every time I see that I am not a respected member of this community.