Advertisement
Guest User

ULX Respawn

a guest
Nov 26th, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.31 KB | None | 0 0
  1. --[Respawn]------------------------------------------------------------------------------------
  2. --[[ulx.respawn][Respawns <target(s)>]
  3. @param {[PlayerObject]} calling_ply [The player who used the command.]
  4. @param {[PlayerObject]} target_plys [The player(s) who will have the effects of the command applied to them.]
  5. @param {[Boolean]} should_silent [Hidden, determines weather the output will be silent or not.]
  6. --]]
  7. function ulx.respawn( calling_ply, target_plys, should_silent )
  8. if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  9. local affected_plys = {}
  10.  
  11. for i=1, #target_plys do
  12. local v = target_plys[ i ]
  13.  
  14. if ulx.getExclusive( v, calling_ply ) then
  15. ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
  16. elseif GetRoundState() == 1 then
  17. ULib.tsayError( calling_ply, "Waiting for players!", true )
  18.  
  19. elseif v:Alive() and v:IsSpec() then -- players arent really dead when they are spectating, we need to handle that correctly
  20. timer.Destroy("traitorcheck" .. v:SteamID())
  21. v:ConCommand("ttt_spectator_mode 0") -- just incase they are in spectator mode take them out of it
  22. timer.Create("respawndelay", 0.1, 0, function() --seems to be a slight delay from when you leave spec and when you can spawn this should get us around that
  23. local corpse = corpse_find(v) -- run the normal respawn code now
  24. if corpse then corpse_remove(corpse) end
  25.  
  26. v:SpawnForRound( true )
  27. v:SetCredits( ( (v:GetRole() == ROLE_INNOCENT) and 0 ) or GetConVarNumber("ttt_credits_starting") )
  28.  
  29. table.insert( affected_plys, v )
  30.  
  31. ulx.fancyLogAdmin( calling_ply, should_silent ,"#A respawned #T!", affected_plys )
  32. send_messages(affected_plys, "You have been respawned.")
  33.  
  34. if v:Alive() then timer.Destroy("respawndelay") return end
  35. end)
  36.  
  37. elseif v:Alive() then
  38. ULib.tsayError( calling_ply, v:Nick() .. " is already alive!", true )
  39. else
  40. timer.Destroy("traitorcheck" .. v:SteamID())
  41. local corpse = corpse_find(v)
  42. if corpse then corpse_remove(corpse) end
  43.  
  44. v:SpawnForRound( true )
  45. v:SetCredits( ( (v:GetRole() == ROLE_INNOCENT) and 0 ) or GetConVarNumber("ttt_credits_starting") )
  46.  
  47. table.insert( affected_plys, v )
  48. end
  49. end
  50. ulx.fancyLogAdmin( calling_ply, should_silent ,"#A respawned #T!", affected_plys )
  51. send_messages(affected_plys, "You have been respawned.")
  52. end
  53. end
  54. local respawn = ulx.command( CATEGORY_NAME, "ulx respawn", ulx.respawn, "!respawn")
  55. respawn:addParam{ type=ULib.cmds.PlayersArg }
  56. respawn:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  57. respawn:defaultAccess( ULib.ACCESS_SUPERADMIN )
  58. respawn:setOpposite( "ulx srespawn", {_, _, true}, "!srespawn", true )
  59. respawn:help( "Respawns <target(s)>." )
  60. --[End]----------------------------------------------------------------------------------------
  61.  
  62.  
  63.  
  64. --[Respawn teleport]---------------------------------------------------------------------------
  65. --[[ulx.respawntp][Respawns <target(s)>]
  66. @param {[PlayerObject]} calling_ply [The player who used the command.]
  67. @param {[PlayerObject]} target_ply [The player who will have the effects of the command applied to them.]
  68. @param {[Boolean]} should_silent [Hidden, determines weather the output will be silent or not.]
  69. --]]
  70. function ulx.respawntp( calling_ply, target_ply, should_silent )
  71. if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
  72.  
  73. local affected_ply = {}
  74. if not calling_ply:IsValid() then
  75. Msg( "You are the console, you can't teleport or teleport others since you can't see the world!\n" )
  76. return
  77. elseif ulx.getExclusive( target_ply, calling_ply ) then
  78. ULib.tsayError( calling_ply, ulx.getExclusive( target_ply, calling_ply ), true )
  79. elseif GetRoundState() == 1 then
  80. ULib.tsayError( calling_ply, "Waiting for players!", true )
  81.  
  82. elseif target_ply:Alive() and target_ply:IsSpec() then
  83. timer.Destroy("traitorcheck" .. target_ply:SteamID())
  84. target_ply:ConCommand("ttt_spectator_mode 0")
  85. timer.Create("respawntpdelay", 0.1, 0, function() --have to wait for gamemode before doing this
  86. local t = {}
  87. t.start = calling_ply:GetPos() + Vector( 0, 0, 32 ) -- Move them up a bit so they can travel across the ground
  88. t.endpos = calling_ply:GetPos() + calling_ply:EyeAngles():Forward() * 16384
  89. t.filter = target_ply
  90. if target_ply ~= calling_ply then
  91. t.filter = { target_ply, calling_ply }
  92. end
  93. local tr = util.TraceEntity( t, target_ply )
  94.  
  95. local pos = tr.HitPos
  96.  
  97. local corpse = corpse_find(target_ply)
  98. if corpse then corpse_remove(corpse) end
  99.  
  100. target_ply:SpawnForRound( true )
  101. target_ply:SetCredits( ((target_ply:GetRole() == ROLE_INNOCENT) and 0) or GetConVarNumber("ttt_credits_starting") )
  102.  
  103. target_ply:SetPos( pos )
  104. table.insert( affected_ply, target_ply )
  105.  
  106. ulx.fancyLogAdmin( calling_ply, should_silent ,"#A respawned and teleported #T!", affected_ply )
  107. send_messages(target_ply, "You have been respawned and teleported.")
  108.  
  109. if target_ply:Alive() then timer.Destroy("respawntpdelay") return end
  110. end)
  111.  
  112. elseif target_ply:Alive() then
  113. ULib.tsayError( calling_ply, target_ply:Nick() .. " is already alive!", true )
  114. else
  115. timer.Destroy("traitorcheck" .. target_ply:SteamID())
  116. local t = {}
  117. t.start = calling_ply:GetPos() + Vector( 0, 0, 32 ) -- Move them up a bit so they can travel across the ground
  118. t.endpos = calling_ply:GetPos() + calling_ply:EyeAngles():Forward() * 16384
  119. t.filter = target_ply
  120. if target_ply ~= calling_ply then
  121. t.filter = { target_ply, calling_ply }
  122. end
  123. local tr = util.TraceEntity( t, target_ply )
  124.  
  125. local pos = tr.HitPos
  126.  
  127. local corpse = corpse_find(target_ply)
  128. if corpse then corpse_remove(corpse) end
  129.  
  130. target_ply:SpawnForRound( true )
  131. target_ply:SetCredits( ((target_ply:GetRole() == ROLE_INNOCENT) and 0) or GetConVarNumber("ttt_credits_starting") )
  132.  
  133. target_ply:SetPos( pos )
  134. table.insert( affected_ply, target_ply )
  135. end
  136. ulx.fancyLogAdmin( calling_ply, should_silent ,"#A respawned and teleported #T!", affected_ply )
  137. send_messages(affected_plys, "You have been respawned and teleported.")
  138. end
  139. end
  140. local respawntp = ulx.command( CATEGORY_NAME, "ulx respawntp", ulx.respawntp, "!respawntp")
  141. respawntp:addParam{ type=ULib.cmds.PlayerArg }
  142. respawntp:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  143. respawntp:defaultAccess( ULib.ACCESS_SUPERADMIN )
  144. respawntp:setOpposite( "ulx srespawntp", {_, _, true}, "!srespawntp", true )
  145. respawntp:help( "Respawns <target> to a specific location." )
  146. --[End]----------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement