Ulysses

General => Developers Corner => Topic started by: Solunae on June 12, 2013, 01:04:49 PM

Title: ulx luarun question (coding)
Post by: Solunae on June 12, 2013, 01:04:49 PM
So I wrote a simple Lua to spawn a entity.

Code: [Select]
c4 = ents.Create("ttt_c4")
aPlayer=ply:GetShootPos()
c4:SetPos(aPlayer)
c4:Spawn()
c4:SetDetonateTimer(100)
c4:SetArmed(true)

Entering this with the normal Lua_run in console on my listen server it will work as it should and spawn the entity on my shootpos.

But when I use this with the ulx luarun on a dedicated server it will not spawn this as ply is empty (I understand this).

Is there anyway I could have it spawn on me or by entering a player name using the ULX luarun?
Title: Re: ulx luarun question (coding)
Post by: Megiddo on June 12, 2013, 02:19:12 PM
If you're the first person to join the server since it has started (or possibly changed maps, not sure), you can use "Entity(1)" (or if you know your entid, use that instead). Otherwise, you could use ULib.getUser (http://ulyssesmod.net/docs/files/lua/ulib/shared/player-lua.html#getUser) to do name matching.
Title: Re: ulx luarun question (coding)
Post by: Solunae on June 12, 2013, 02:25:25 PM
So basically I would need something like.

Code: [Select]
c4 = ents.Create("ttt_c4")
Target = ULib.getUser("Solunae")
aPlayer = Target:GetShootPos()
c4:SetPos(aPlayer)
c4:Spawn()
c4:SetDetonateTimer(100)
c4:SetArmed(true)

Correct? or am I missing something.


*Edit*
The following code was the first Lua I ever made and it worked. But the problem in this one was finding a specific player entity ID. If there is a easy way to retrieve someones ID off a dedicated server with ULX installed that would work fine too. (I'm not the owner off this server but a superadmin with lua, rcon, exec)

Also they don't seem to work with the ulx luarun (might have format wrong) in console, but they do work in the ULX menu Lua run

Code: [Select]
c4=ents.Create("ttt_c4")
Target=player.GetByID(1):GetShootPos()
c4:Spawn() c4:SetPos(Target)
c4:SetDetonateTimer(100)
c4:SetArmed(true)

Code: [Select]
c4=ents.Create("ttt_c4")
Target=player.GetAll()
c4:Spawn()
c4:SetPos(Target[5]:GetShootPos())
c4:SetDetonateTimer(1)
c4:SetArmed(true)




Alright, this code works with the name finding. At first it seemed to fail untill I tried it in the actual ULX menu and not the ulx luarun in console.

Code: [Select]
c4 = ents.Create("ttt_c4")
Target = ULib.getUser("Solunae")
aPlayer = Target:GetShootPos()
c4:SetPos(aPlayer)
c4:Spawn()
c4:SetDetonateTimer(100)
c4:SetArmed(true)

Thanks for the assistance.
Title: Re: ulx luarun question (coding)
Post by: JamminR on June 12, 2013, 03:30:27 PM
See MrPresident's "ulx explode (http://forums.ulyssesmod.net/index.php/topic,3324)" in our releases section.
Though written in ULX command format, it passes players (plural) in a table to the function, then uses for loop to do various fun things.
Also, it's not been touched since years before (http://forums.ulyssesmod.net/index.php/topic,3324.msg16928.html#msg16928) Gmod13 came out.
Don't expect it to work as-is, just use it as an example of passing in the playerid.
Seems your idea wants to do the same...explode a player or something like that.
Title: Re: ulx luarun question (coding)
Post by: Megiddo on June 12, 2013, 03:48:00 PM
He wants to do it specifically from his console, JamminR.