HR_Shaft

Vehicle Anticamp for Phasor v2+

Nov 16th, 2014
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.75 KB | None | 0 0
  1. -- Vehicle Anticamp v1.1.1
  2. -- created by 002 for SAPP
  3. -- converted from SAPP to Phasor by H® Shaft for Phasor v2+
  4.  
  5. -- This script will monitor, warn and take action on players camping in vehicles.  If players remain too long in one area, the script takes the selected action.
  6.  
  7. -- These are the lists of vehicles to monitor, separated by commas. They do not have to be present in all of the maps.
  8. VEHICLES_TO_MONITOR = {
  9. "vehicles\\scorpion\\scorpion_mp",
  10. "vehicles\\rwarthog\\rwarthog",
  11. "vehicles\\warthog\\mp_warthog",
  12. "vehicles\\ghost\\ghost_mp"
  13. }
  14.  
  15. -- Interval in which this script scans players for camping. This is in seconds.
  16. CYCLE_TIME = 5
  17.  
  18. -- The player must have moved this many world units since the last cycle, or else they are still camping.
  19. UNCAMP_THRESHOLD = 10
  20.  
  21. -- Time until the player is warned to move. Set it to 0 to emit no warning.
  22. CAMP_WARN_TIME = 15
  23.  
  24. -- This message is sent to the player upon warning. Set it to "" to emit no message.
  25. CAMP_WARN_MESSAGE = "Move! or you will be killed/ejected for camping."
  26.  
  27. -- Time until action is taken
  28. CAMP_ACTION_TIME = 25
  29.  
  30. -- This message is sent to the player upon action being taken.
  31. CAMP_ACTION_MESSAGE = "You were killed (or) ejected for camping."
  32.  
  33. -- Actions to take on the player.
  34. -- 1 = Remove the player from the vehicle.
  35. -- 2 = Kill the player.
  36. -- 3 = Kill the player without a death message.
  37. CAMP_ACTION_PLAYER = 3
  38.  
  39. -- Respawn the vehicle as well. Please note that this requires that vehicle respawning be enabled in the gametype.
  40. CAMP_ACTION_RESPAWN_VEHICLE = true
  41.  
  42. -- Ignore players that are admins? true = ignore, false = take action
  43. -- if an admin is a vehicle driver, passengers/gunners will not be warned/killed if driver is not moving
  44. IGNORE_ADMIN = false
  45.  
  46. -- Overrides VEHICLES_TO_MONITOR and  monitors every single vehicle (including stationary turrets = bad) AND admin players too.
  47. MONITOR_ALL_VEHICLES = false
  48.  
  49. -- {CampTime, X, Y, Z, Warned}
  50. last_position = {}
  51. respawn_queue = {}
  52.  
  53. function GetRequiredVersion()
  54.     return 200
  55. end
  56.  
  57. function OnScriptLoad(process, game, persistent)
  58.     oncycle =  registertimer(1000 * CYCLE_TIME, "OnCycle")
  59.     ontick = registertimer(33.333333, "OnTick")
  60.     for i=0,15 do
  61.         if getplayer(i) then
  62.             last_position[i] = nil
  63.             respawn_queue[i] = {}
  64.         end
  65.     end
  66. end
  67.  
  68. function OnPlayerJoin(player)
  69.     if getplayer(player) then
  70.         last_position[player] = nil
  71.         respawn_queue[player] = {}
  72.     end
  73. end
  74.  
  75. function OnPlayerLeave(player)
  76.     if getplayer(player) then
  77.         last_position[player] = nil
  78.         respawn_queue[player] = nil
  79.     end
  80. end
  81.  
  82. function OnTick()
  83.     for i=0,15 do
  84.         if getplayer(i) then
  85.             if (respawn_queue[i] ~= nil) then
  86.                 local respawn_vehicle = false
  87.                 if not player_alive(i) then
  88.                     respawn_vehicle = true
  89.                 else
  90.                     if isinvehicle(i) then
  91.                         local m_player = getplayer(i)
  92.                         local m_objectId = readdword(m_player + 0x34)
  93.                         local m_object = getobject(m_objectId)
  94.                         if m_object then
  95.                             local m_vehicleId = readdword(m_object + 0x11C)
  96.                             local m_vehicle = getobject(m_vehicleId)
  97.                             if not m_vehicle then respawn_vehicle = true end
  98.                         end
  99.                         if respawn_vehicle then
  100.                             writedword(respawn_queue[i] + 0x5ac, readdword(respawn_queue[i] + 0x5ac) - 0x100000)
  101.                             respawn_queue[i] = nil
  102.                         end
  103.                     end
  104.                 end
  105.             end
  106.         end
  107.     end
  108.     return true
  109. end
  110.  
  111. function PlayerInsideMonitoredVehicle(player)
  112.     local bool = false
  113.     if getplayer(player) then
  114.         if isadmin(player) then bool = true end
  115.         if IGNORE_ADMIN and bool then return false end
  116.         if player_alive(player) then    
  117.             if isinvehicle(player) then
  118.                 local m_player = getplayer(player)
  119.                 local m_objectId = readdword(m_player + 0x34)
  120.                 local m_object = getobject(m_objectId)
  121.                 if m_object then
  122.                     local m_vehicleId = readdword(m_object + 0x11C)
  123.                     local m_vehicle = getobject(m_vehicleId)
  124.                     local vehname = gettaginfo(readdword(m_vehicle))
  125.                     if m_vehicle then
  126.                         local tablesize = #VEHICLES_TO_MONITOR
  127.                         for v=1,tablesize do
  128.                             if VEHICLES_TO_MONITOR[v] == vehname then return true end
  129.                         end
  130.                     else
  131.                         return false
  132.                     end
  133.                 end
  134.             else
  135.                 return false
  136.             end
  137.         else
  138.             return false
  139.         end
  140.         if MONITOR_ALL_VEHICLES and bool then
  141.             return false
  142.         elseif MONITOR_ALL_VEHICLES and not bool then
  143.             return true
  144.         end
  145.     end
  146.     return false
  147. end
  148.  
  149. function Distance(x1,y1,z1,x2,y2,z2)
  150.     return math.sqrt((x1 - x2) ^ 2 + (y1 - y2) ^ 2 + (z1 - z2) ^ 2)
  151. end
  152.  
  153. function KillPlayerSilently(player)
  154.     if getplayer(player) then
  155.         local m_player = getplayer(player)
  156.         local old_value = readword(m_player + 0xD4)
  157.         writeword(m_player + 0xD4, 0xFFFF)
  158.         kill(player)
  159.         writeword(m_player + 0xD4, old_value)
  160.     end
  161. end
  162.  
  163. function getdriverplayer(m_vehicle)
  164.     local obj_id = readdword(m_vehicle + 0x324)
  165.     if obj_id and obj_id ~= 0xFFFFFFFF then return objectidtoplayer(obj_id) end
  166. end
  167.  
  168. function player_alive(player)
  169.     if getplayer(player) then
  170.         local m_objectId = getplayerobjectid(player)
  171.         if m_objectId then
  172.             local m_object = getobject(m_objectId)
  173.             if m_object then
  174.                 return true
  175.             else
  176.                 return false
  177.             end
  178.         end
  179.     end
  180. end
  181.  
  182. function OnPlayerKill(killer, victim, mode)
  183.     if getplayer(victim) then
  184.         last_position[victim] = nil
  185.     end
  186. end
  187.  
  188. function OnVehicleEntry(player, m_vehicleId, seat, mapid, relevant)
  189.     if player then
  190.         local m_player = getplayer(player)
  191.         if m_player and player_alive then
  192.             local m_objectId = readdword(m_player + 0x34)
  193.             if m_objectId then
  194.                 local time = os.clock()
  195.                 local x,y,z = getobjectcoords(m_objectId)
  196.                 last_position[player] = {}
  197.                 last_position[player][1] = time
  198.                 last_position[player][2] = x
  199.                 last_position[player][3] = y
  200.                 last_position[player][4] = z   
  201.                 last_position[player][5] = false
  202.             end
  203.             local m_vehicle = getobject(m_vehicleId)   
  204.             if IGNORE_ADMIN and isadmin(player) then last_position[player] = nil end
  205.             local driver = readdword(m_vehicle + 0x324)
  206.             if seat ~= 0 and IGNORE_ADMIN then
  207.                 if driver ~= 0xFFFFFFFF then
  208.                     local m_vehicle = getobject(m_vehicleId)
  209.                     local driverplayer = getdriverplayer(m_vehicle)
  210.                     if isadmin(driverplayer) then
  211.                         last_position[player] = nil
  212.                     end    
  213.                 end    
  214.             end
  215.         end
  216.     end    
  217.     return nil
  218. end
  219.  
  220. function OnVehicleEject(player, relevant)
  221.     if getplayer(player) then
  222.         last_position[player] = nil
  223.     end
  224.     return nil
  225. end
  226.  
  227. function OnCycle()
  228.     local time = os.clock()
  229.     for i=0,15 do
  230.         if getplayer(i) then
  231.             if PlayerInsideMonitoredVehicle(i) then
  232.                 local m_player = getplayer(i)
  233.                 local m_objectId = readdword(m_player + 0x34)
  234.                 if m_objectId then
  235.                     local m_object = getobject(m_objectId)
  236.                     if m_object then
  237.                         local x,y,z = getobjectcoords(m_objectId)
  238.                         local m_vehicleId = readdword(getobject(m_objectId) + 0x11C)
  239.                         local m_vehicle = getobject(m_vehicleId)
  240.                         local driver = readdword(m_vehicle + 0x324)                    
  241.                         if last_position[i] == nil then
  242.                             last_position[i] = {}
  243.                             last_position[i][1] = time
  244.                             last_position[i][2] = x
  245.                             last_position[i][3] = y
  246.                             last_position[i][4] = z
  247.                             last_position[i][5] = false                
  248.                         elseif Distance(last_position[i][2],last_position[i][3],last_position[i][4],x,y,z) >= UNCAMP_THRESHOLD then
  249.                             last_position[i] = nil
  250.                         elseif IGNORE_ADMIN and isadmin(i) then
  251.                             last_position[i] = nil
  252.                         elseif IGNORE_ADMIN and driver ~= 0xFFFFFFFF then
  253.                             local driverplayer = getdriverplayer(m_vehicle)
  254.                             if isadmin(driverplayer) then
  255.                                 last_position[i] = nil
  256.                             end                                    
  257.                         else
  258.                             last_position[i][2] = x
  259.                             last_position[i][3] = y
  260.                             last_position[i][4] = z
  261.                             if time > (last_position[i][1] + CAMP_WARN_TIME) and (last_position[i][5] == false) then
  262.                                 privatesay(i, getname(i).. " " .. CAMP_WARN_MESSAGE)
  263.                                 last_position[i][5] = true                                                         
  264.                             elseif time > (last_position[i][1] + CAMP_ACTION_TIME) and (last_position[i][5] == true) then
  265.                                 if CAMP_ACTION_RESPAWN_VEHICLE then
  266.                                     local m_vehicleId = readdword(getobject(m_objectId) + 0x11C)
  267.                                     local m_object = getobject(m_vehicleId)
  268.                                     respawn_queue[i] = m_object
  269.                                 end
  270.                                 if CAMP_ACTION_PLAYER == 1 then
  271.                                     exitvehicle(i)
  272.                                 elseif CAMP_ACTION_PLAYER == 2 then
  273.                                     kill(i)
  274.                                 elseif CAMP_ACTION_PLAYER == 3 then
  275.                                     KillPlayerSilently(i)
  276.                                 end
  277.                                 privatesay(i, getname(i).. " " .. CAMP_ACTION_MESSAGE)
  278.                             end
  279.                         end
  280.                     end
  281.                 end    
  282.             else
  283.                 last_position[i] = nil
  284.             end
  285.         end
  286.     end
  287.     return true
  288. end
  289.  
  290. -- Created by H® Shaft thank you to Oxide, AelitePrime, Nugget & Wizard.
  291. -- Visit http://halorace.org/forum/index.php?topic=514.0 or
  292. -- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
Advertisement
Add Comment
Please, Sign In to add comment