Advertisement
Combreal

VehiAnticamp.lua

Dec 2nd, 2022
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.12 KB | Gaming | 0 0
  1. -- Vehicle Anticamp by 002 v1.1.2
  2. -- Configuration
  3. -- Writen by Kavawuvi
  4.  
  5.  
  6. -- These are the lists of vehicles to monitor, separated by commas. They do not have to be present in all of the maps.
  7. -- Note that two backslashes are required for each backslash, or else the script will fail to work.
  8. VEHICLES_TO_MONITOR = {
  9. "vehicles\\scorpion\\scorpion_mp",
  10. "vehicles\\rwarthog\\rwarthog",
  11. "vehicles\\warthog\\mp_warthog"
  12. }
  13.  
  14. -- Overrides VEHICLES_TO_MONITOR and just monitors every single vehicle.
  15. MONITOR_ALL_VEHICLES = false
  16.  
  17. -- Interval in which this script scans players for camping. This is in seconds.
  18. CYCLE_TIME = 5
  19.  
  20. -- The player must have moved this many world units since the last cycle, or else they are still camping.
  21. UNCAMP_THRESHOLD = 5
  22.  
  23. -- Time until the player is warned to move. Set it to 0 to emit no warning.
  24. CAMP_WARN_TIME = 25
  25.  
  26. -- This message is sent to the player upon warning. Set it to "" to emit no message.
  27. CAMP_WARN_MESSAGE = "Move, or you will be kicked out of your vehicle."
  28.  
  29. -- Time until action is taken
  30. CAMP_ACTION_TIME = 30
  31.  
  32. -- This message is sent to the player upon action being taken.
  33. CAMP_ACTION_MESSAGE = "You were kicked out of your vehicle for camping."
  34.  
  35. -- Actions to take on the player.
  36. -- 1 = Remove the player from the vehicle.
  37. -- 2 = Kill the player.
  38. -- 3 = Kill the player without a death message.
  39. CAMP_ACTION_PLAYER = 1
  40.  
  41. -- Respawn the vehicle as well. Please note that this requires that vehicle respawning be enabled in the gametype.
  42. CAMP_ACTION_RESPAWN_VEHICLE = true
  43.  
  44. -- Ignore players that are at least this admin level. Set to 5 or more to disable this feature.
  45. -- Refer to xhalo.tk for more information on admin levels.
  46. IGNORE_ADMIN_LEVEL = 5
  47.  
  48. -- End of configuration
  49.  
  50.  
  51. api_version = "1.6.0.0"
  52.  
  53. -- {CampTime, X, Y, Z, Warned}
  54. last_position = {}
  55.  
  56. respawn_queue = {}
  57.  
  58.  
  59. function OnScriptLoad()
  60.     register_callback(cb['EVENT_TICK'],"OnTick")
  61.     register_callback(cb['EVENT_LEAVE'],"OnPlayerLeave")
  62.     timer(1000 * CYCLE_TIME,"OnCycle")
  63. end
  64. function OnScriptUnload() end
  65.  
  66. function OnPlayerLeave(PlayerIndex)
  67.     last_position[PlayerIndex] = nil
  68. end
  69.  
  70. function OnTick()
  71.     for i=1,16 do
  72.         if(respawn_queue[i] ~= nil) then
  73.             local respawn_vehicle = false
  74.             if(player_alive(i) == false) then
  75.                 respawn_vehicle = true
  76.             else
  77.                 local player_object = get_dynamic_player(i)
  78.                 local vehicle_objectid = read_dword(player_object + 0x11C)
  79.                 local vehicle_object = get_object_memory(vehicle_objectid)
  80.                 if(vehicle_object == 0) then respawn_vehicle = true end
  81.             end
  82.             if(respawn_vehicle == true) then
  83.                 write_dword(respawn_queue[i] + 0x5ac,read_dword(respawn_queue[i] + 0x5ac) - 0x100000)
  84.                 respawn_queue[i] = nil
  85.             end
  86.         end
  87.     end
  88. end
  89.  
  90. function PlayerInsideMonitoredVehicle(PlayerIndex)
  91.     if(player_alive(PlayerIndex) == false) then return false end
  92.     if(tonumber(get_var(PlayerIndex,"$lvl")) >= IGNORE_ADMIN_LEVEL) then return false end
  93.     local player_object = get_dynamic_player(PlayerIndex)
  94.     local vehicle_objectid = read_dword(player_object + 0x11C)
  95.     local vehicle_object = get_object_memory(vehicle_objectid)
  96.     if(vehicle_object == 0) then return false end
  97.     if(MONITOR_ALL_VEHICLES == true) then return true end
  98.  
  99.     local vehicle_tag_index = read_word(vehicle_object)
  100.     local vehicle_tag_entry = read_dword(0x40440000) + 0x20 * vehicle_tag_index
  101.     local vehicle_name = read_string(read_dword(vehicle_tag_entry + 0x10))
  102.  
  103.     for q=1,#VEHICLES_TO_MONITOR do
  104.         if(VEHICLES_TO_MONITOR[q] == vehicle_name) then return true end
  105.     end
  106.  
  107.     return false
  108. end
  109.  
  110. function Distance(x1,y1,z1,x2,y2,z2)
  111.     return math.sqrt(math.pow(x1 - x2,2) + math.pow(y1 - y2,2) + math.pow(z1 - z2,2))
  112. end
  113.  
  114. function KillPlayerSilently(PlayerIndex)
  115.     local player = get_player(PlayerIndex)
  116.     -- Silently kill the player
  117.     local old_value = read_word(player + 0xD4)
  118.     --write_dword(player + 0x30, 30 * UNAUTHORIZED_KICK_TIME - read_dword(gametype_pointer ))
  119.     write_word(player + 0xD4, 0xFFFF)
  120.     kill(PlayerIndex)
  121.     write_word(player + 0xD4, old_value)
  122. end
  123.  
  124. function OnCycle()
  125.     local time = os.clock()
  126.     for i=1,16 do
  127.         if(PlayerInsideMonitoredVehicle(i) == true) then
  128.             local player_object = get_dynamic_player(i)
  129.             local vehicle_objectid = read_dword(player_object + 0x11C)
  130.             local vehicle_object = get_object_memory(vehicle_objectid)
  131.             local x,y,z = read_vector3d(vehicle_object + 0x5C)
  132.             if(last_position[i] == nil) then
  133.                 last_position[i] = {time,x,y,z,CAMP_WARN_TIME == 0}
  134.             elseif(Distance(last_position[i][2],last_position[i][3],last_position[i][4],x,y,z) >= UNCAMP_THRESHOLD) then
  135.                 last_position[i] = nil
  136.             else
  137.                 last_position[i][2] = x
  138.                 last_position[i][3] = y
  139.                 last_position[i][4] = z
  140.                 if(time > (last_position[i][1] + CAMP_WARN_TIME) and last_position[i][5] == false) then
  141.                     say(i,CAMP_WARN_MESSAGE)
  142.                     last_position[i][5] = true
  143.                 end
  144.                 if(time > (last_position[i][1] + CAMP_ACTION_TIME)) then
  145.                     if(CAMP_ACTION_RESPAWN_VEHICLE == true) then
  146.                         local vehicle_objectid = read_dword(player_object + 0x11C)
  147.                         local vehicle_object = get_object_memory(vehicle_objectid)
  148.                         respawn_queue[i] = vehicle_object
  149.                     end
  150.                     if(CAMP_ACTION_PLAYER == 1) then
  151.                         exit_vehicle(i)
  152.                     elseif(CAMP_ACTION_PLAYER == 2) then
  153.                         kill(i)
  154.                     elseif(CAMP_ACTION_PLAYER == 3) then
  155.                         KillPlayerSilently(i)
  156.                     end
  157.                     if(CAMP_ACTION_MESSAGE ~= "") then say(i,CAMP_ACTION_MESSAGE) end
  158.                 end
  159.             end
  160.         else
  161.             last_position[i] = nil
  162.         end
  163.     end
  164.     return true
  165. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement