Author Topic: Porting a plugin/command to ULX  (Read 2333 times)

0 Members and 2 Guests are viewing this topic.

Offline Sea Cucumber

  • Newbie
  • *
  • Posts: 2
  • Karma: 1
Porting a plugin/command to ULX
« on: March 26, 2014, 01:49:02 AM »
Hello :)
currently I'm using serverguard on my server but have realized that I prefer ulx much more. I have a command in serverguard that will revive players when they are dead and bring them to life where they spawned with everything they had before they died. I'm a beginner so I don't have the best knowledge on how to port this and make it work in ULX but if someone could shed some light and help me that would be greatly appreciated!

-snip-

Problem has been solved, thread can be closed.
« Last Edit: March 26, 2014, 02:18:31 PM by Sea Cucumber »

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: Porting a plugin/command to ULX
« Reply #1 on: March 26, 2014, 12:58:40 PM »
Untested, but try this:

Code: [Select]
function ulx.revive( calling_ply, target_ply )
local wepstab = target_ply.savedweapons or nil
local savedpos = target_ply.savedpos or nil
if not ( wepstab and savedpos ) then
calling_ply:ChatPrint( "This player does not have any saved data." )
return
end
if not target_ply:IsValid() then
return
end
target_ply:Spawn()
target_ply:SetPos( savedpos )
target_ply:SetLocalVelocity( Vector( 0, 0, 0, ) )
target_ply:StripWeapons()
for k, v in next, wepstab do
target_ply:Give( v )
end

ulx.fancyLogAdmin( calling_ply, "#A revived #T", target_ply )
end
local rw = ulx.command( "Utility", "ulx revive", ulx.revive, { "!restore", "!revive" } )
rw:addParam{ type=ULib.cmds.PlayerArg }
rw:defaultAccess( ULib.ACCESS_SUPERADMIN )
rw:help( "Restore a player's weapons" )

if ( SERVER ) then
hook.Add( "PlayerDeath", "SaveWeapons", function( ply )
ply.savedweapons = {}
for k, v in next, ply:GetWeapons() do
table.insert( ply.savedweapons, v:GetClass() )
end
ply.savedpos = ply:GetPos()
end )
end
« Last Edit: March 26, 2014, 01:01:55 PM by Cobalt »

Offline Sea Cucumber

  • Newbie
  • *
  • Posts: 2
  • Karma: 1
Re: Porting a plugin/command to ULX
« Reply #2 on: March 26, 2014, 01:11:09 PM »
You had an extra comma on target_ply:SetLocalVelocity( Vector( 0, 0, 0, ) ) but I fixed that and the code works. You don't know how much this helps me. Thanks man.

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: Porting a plugin/command to ULX
« Reply #3 on: March 26, 2014, 04:55:10 PM »
You had an extra comma on target_ply:SetLocalVelocity( Vector( 0, 0, 0, ) ) but I fixed that and the code works. You don't know how much this helps me. Thanks man.
Cool, glad I could help!