jay5476

ulx return

Jan 10th, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.46 KB | None | 0 0
  1. CATEGORY_NAME = "Teleport"
  2.  
  3. -- Utility function for bring, goto, and send
  4. local function playerSend( from, to, force )
  5. if not to:IsInWorld() and not force then return false end -- No way we can do this one
  6. -- Save their position and eye angles
  7. from.ReturnPoint = from:GetPos()
  8. from.ReturnAngles = from:GetAngles()
  9.  
  10. local yawForward = to:EyeAngles().yaw
  11. local directions = { -- Directions to try
  12. math.NormalizeAngle( yawForward - 180 ), -- Behind first
  13. math.NormalizeAngle( yawForward + 90 ), -- Right
  14. math.NormalizeAngle( yawForward - 90 ), -- Left
  15. yawForward,
  16. }
  17.  
  18. local t = {}
  19. t.start = to:GetPos() + Vector( 0, 0, 32 ) -- Move them up a bit so they can travel across the ground
  20. t.filter = { to, from }
  21.  
  22. local i = 1
  23. t.endpos = to:GetPos() + Angle( 0, directions[ i ], 0 ):Forward() * 47 -- (33 is player width, this is sqrt( 33^2 * 2 ))
  24. local tr = util.TraceEntity( t, from )
  25. while tr.Hit do -- While it's hitting something, check other angles
  26. i = i + 1
  27. if i > #directions then -- No place found
  28. if force then
  29. return to:GetPos() + Angle( 0, directions[ 1 ], 0 ):Forward() * 47
  30. else
  31. return false
  32. end
  33. end
  34.  
  35. t.endpos = to:GetPos() + Angle( 0, directions[ i ], 0 ):Forward() * 47
  36.  
  37. tr = util.TraceEntity( t, from )
  38. end
  39.  
  40. return tr.HitPos
  41. end
  42.  
  43. function ulx.bring( calling_ply, target_ply )
  44. if not calling_ply:IsValid() then
  45. Msg( "If you brought someone to you, they would instantly be destroyed by the awesomeness that is console.\n" )
  46. return
  47. end
  48.  
  49. if ulx.getExclusive( calling_ply, calling_ply ) then
  50. ULib.tsayError( calling_ply, ulx.getExclusive( calling_ply, calling_ply ), true )
  51. return
  52. end
  53.  
  54. if ulx.getExclusive( target_ply, calling_ply ) then
  55. ULib.tsayError( calling_ply, ulx.getExclusive( target_ply, calling_ply ), true )
  56. return
  57. end
  58.  
  59. if not target_ply:Alive() then
  60. ULib.tsayError( calling_ply, target_ply:Nick() .. " is dead!", true )
  61. return
  62. end
  63.  
  64. if not calling_ply:Alive() then
  65. ULib.tsayError( calling_ply, "You are dead!", true )
  66. return
  67. end
  68.  
  69. if calling_ply:InVehicle() then
  70. ULib.tsayError( calling_ply, "Please leave the vehicle first!", true )
  71. return
  72. end
  73.  
  74. local newpos = playerSend( target_ply, calling_ply, target_ply:GetMoveType() == MOVETYPE_NOCLIP )
  75. if not newpos then
  76. ULib.tsayError( calling_ply, "Can't find a place to put the target!", true )
  77. return
  78. end
  79.  
  80. if target_ply:InVehicle() then
  81. target_ply:ExitVehicle()
  82. end
  83.  
  84. local newang = (calling_ply:GetPos() - newpos):Angle()
  85.  
  86. target_ply:SetPos( newpos )
  87. target_ply:SetEyeAngles( newang )
  88. target_ply:SetLocalVelocity( Vector( 0, 0, 0 ) ) -- Stop!
  89.  
  90. ulx.fancyLogAdmin( calling_ply, "#A brought #T", target_ply )
  91. end
  92. local bring = ulx.command( CATEGORY_NAME, "ulx bring", ulx.bring, "!bring" )
  93. bring:addParam{ type=ULib.cmds.PlayerArg, target="!^" }
  94. bring:defaultAccess( ULib.ACCESS_ADMIN )
  95. bring:help( "Brings target to you." )
  96.  
  97. function ulx.goto( calling_ply, target_ply )
  98. if not calling_ply:IsValid() then
  99. Msg( "You may not step down into the mortal world from console.\n" )
  100. return
  101. end
  102.  
  103. if ulx.getExclusive( calling_ply, calling_ply ) then
  104. ULib.tsayError( calling_ply, ulx.getExclusive( calling_ply, calling_ply ), true )
  105. return
  106. end
  107.  
  108. if not target_ply:Alive() then
  109. ULib.tsayError( calling_ply, target_ply:Nick() .. " is dead!", true )
  110. return
  111. end
  112.  
  113. if not calling_ply:Alive() then
  114. ULib.tsayError( calling_ply, "You are dead!", true )
  115. return
  116. end
  117.  
  118. if target_ply:InVehicle() and calling_ply:GetMoveType() ~= MOVETYPE_NOCLIP then
  119. ULib.tsayError( calling_ply, "Target is in a vehicle! Noclip and use this command to force a goto.", true )
  120. return
  121. end
  122.  
  123. local newpos = playerSend( calling_ply, target_ply, calling_ply:GetMoveType() == MOVETYPE_NOCLIP )
  124. if not newpos then
  125. ULib.tsayError( calling_ply, "Can't find a place to put you! Noclip and use this command to force a goto.", true )
  126. return
  127. end
  128.  
  129. if calling_ply:InVehicle() then
  130. calling_ply:ExitVehicle()
  131. end
  132.  
  133. local newang = (target_ply:GetPos() - newpos):Angle()
  134.  
  135.  
  136. calling_ply:SetPos( newpos )
  137. calling_ply:SetEyeAngles( newang )
  138. calling_ply:SetLocalVelocity( Vector( 0, 0, 0 ) ) -- Stop!
  139.  
  140. ulx.fancyLogAdmin( calling_ply, "#A teleported to #T", target_ply )
  141. end
  142. local goto = ulx.command( CATEGORY_NAME, "ulx goto", ulx.goto, "!goto" )
  143. goto:addParam{ type=ULib.cmds.PlayerArg, target="!^", ULib.cmds.ignoreCanTarget }
  144. goto:defaultAccess( ULib.ACCESS_ADMIN )
  145. goto:help( "Goto target." )
  146.  
  147. function ulx.send( calling_ply, target_from, target_to )
  148. if target_from == target_to then
  149. ULib.tsayError( calling_ply, "You listed the same target twice! Please use two different targets.", true )
  150. return
  151. end
  152.  
  153. if ulx.getExclusive( target_from, calling_ply ) then
  154. ULib.tsayError( calling_ply, ulx.getExclusive( target_from, calling_ply ), true )
  155. return
  156. end
  157.  
  158. if ulx.getExclusive( target_to, calling_ply ) then
  159. ULib.tsayError( calling_ply, ulx.getExclusive( target_to, calling_ply ), true )
  160. return
  161. end
  162.  
  163. local nick = target_from:Nick() -- Going to use this for our error (if we have one)
  164.  
  165. if not target_from:Alive() or not target_to:Alive() then
  166. if not target_to:Alive() then
  167. nick = target_to:Nick()
  168. end
  169. ULib.tsayError( calling_ply, nick .. " is dead!", true )
  170. return
  171. end
  172.  
  173. if target_to:InVehicle() and target_from:GetMoveType() ~= MOVETYPE_NOCLIP then
  174. ULib.tsayError( calling_ply, "Target is in a vehicle!", true )
  175. return
  176. end
  177.  
  178. local newpos = playerSend( target_from, target_to, target_from:GetMoveType() == MOVETYPE_NOCLIP )
  179. if not newpos then
  180. ULib.tsayError( calling_ply, "Can't find a place to put them!", true )
  181. return
  182. end
  183.  
  184. if target_from:InVehicle() then
  185. target_from:ExitVehicle()
  186. end
  187.  
  188. local newang = (target_from:GetPos() - newpos):Angle()
  189.  
  190. target_from:SetPos( newpos )
  191. target_from:SetEyeAngles( newang )
  192. target_from:SetLocalVelocity( Vector( 0, 0, 0 ) ) -- Stop!
  193.  
  194. ulx.fancyLogAdmin( calling_ply, "#A transported #T to #T", target_from, target_to )
  195. end
  196. local send = ulx.command( CATEGORY_NAME, "ulx send", ulx.send, "!send" )
  197. send:addParam{ type=ULib.cmds.PlayerArg, target="!^" }
  198. send:addParam{ type=ULib.cmds.PlayerArg, target="!^" }
  199. send:defaultAccess( ULib.ACCESS_ADMIN )
  200. send:help( "Goto target." )
  201.  
  202. function ulx.teleport( calling_ply, target_ply )
  203. if not calling_ply:IsValid() then
  204. Msg( "You are the console, you can't teleport or teleport others since you can't see the world!\n" )
  205. return
  206. end
  207.  
  208. if ulx.getExclusive( target_ply, calling_ply ) then
  209. ULib.tsayError( calling_ply, ulx.getExclusive( target_ply, calling_ply ), true )
  210. return
  211. end
  212.  
  213. if not target_ply:Alive() then
  214. ULib.tsayError( calling_ply, target_ply:Nick() .. " is dead!", true )
  215. return
  216. end
  217.  
  218. local t = {}
  219. t.start = calling_ply:GetPos() + Vector( 0, 0, 32 ) -- Move them up a bit so they can travel across the ground
  220. t.endpos = calling_ply:GetPos() + calling_ply:EyeAngles():Forward() * 16384
  221. t.filter = target_ply
  222. if target_ply ~= calling_ply then
  223. t.filter = { target_ply, calling_ply }
  224. end
  225. local tr = util.TraceEntity( t, target_ply )
  226.  
  227. local pos = tr.HitPos
  228.  
  229. if target_ply == calling_ply and pos:Distance( target_ply:GetPos() ) < 64 then -- Laughable distance
  230. return
  231. end
  232.  
  233. if target_ply:InVehicle() then
  234. target_ply:ExitVehicle()
  235. end
  236.  
  237.  
  238. target_ply:SetPos( pos )
  239. target_ply:SetLocalVelocity( Vector( 0, 0, 0 ) ) -- Stop!
  240.  
  241. if target_ply ~= calling_ply then
  242. ulx.fancyLogAdmin( calling_ply, "#A teleported #T", target_ply ) -- We don't want to log otherwise
  243. end
  244. end
  245. local teleport = ulx.command( CATEGORY_NAME, "ulx teleport", ulx.teleport, {"!tp", "!teleport"} )
  246. teleport:addParam{ type=ULib.cmds.PlayerArg, ULib.cmds.optional }
  247. teleport:defaultAccess( ULib.ACCESS_ADMIN )
  248. teleport:help( "Teleports target." )
  249.  
  250. function ulx.ulxreturn(calling_ply, target_ply)
  251. if not target_ply:Alive() then
  252. ULib.tsayError( calling_ply, target_ply:Nick().." is dead!", true)
  253. return
  254. end
  255.  
  256. if target_ply:InVehicle() then
  257. target_ply:ExitVehicle()
  258. end
  259.  
  260. target_ply:SetPos(target_ply.ReturnPoint)
  261. target_ply:SetPos(target_ply.ReturnAngles)
  262.  
  263. if target_ply ~= calling_ply then
  264. ulx.fancyLogAdmin( calling_ply, "#A returned #T", target_ply ) -- We don't want to log otherwise
  265. end
  266. end
  267.  
  268. local ulxreturn = ulx.command( CATEGORY_NAME, "ulx return", ulx.ulxreturn, "!return")
  269. ulxreturn:addParam{ type=ULib.cmds.PlayerArg, ULib.cmds.optional }
  270. ulxreturn:help("Returns the target to their psoition before teleport.")
Advertisement
Add Comment
Please, Sign In to add comment