SHARE
TWEET

vehicle_seats.lua

a guest Dec 24th, 2018 12 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Config
  2.  
  3. -- true or false, whether or not to allow entering seats
  4. ALLOW_DRIVER_SEAT = true
  5. ALLOW_GUNNER_SEAT = true
  6. ALLOW_PASSENGER_SEAT = true
  7.  
  8. -- true or false, whether or not driver is required before other seats can be entered
  9. DRIVER_REQUIRED_FOR_PASSENGERS = false
  10. DRIVER_REQUIRED_FOR_GUNNER = false
  11.  
  12. -- End of Config
  13.  
  14. api_version = "1.9.0.0"
  15.  
  16. function OnScriptLoad()
  17.     register_callback(cb['EVENT_GAME_START'], "OnGameStart")
  18.     if(DRIVER_REQUIRED) then
  19.         register_callback(cb['EVENT_TICK'], "OnTick")
  20.     end
  21. end
  22.  
  23. function OnGameStart()
  24.     for i=0,1 do
  25.         local vehicles_count = nil
  26.         local vehicles_data = nil
  27.         local size = nil
  28.        
  29.         if(i == 0) then
  30.             local globals_tag = lookup_tag("matg", "globals\\globals")
  31.             local globals_data = read_dword(globals_tag + 0x14)
  32.             local mp_info_data = read_dword(globals_data + 0x168)
  33.            
  34.             vehicles_count = read_dword(mp_info_data + 0x20)
  35.             vehicles_data = read_dword(mp_info_data + 0x24)
  36.             size = 16
  37.         else
  38.             local scenario_tag = read_dword(0x40440000)
  39.             local scenario_data = read_dword(scenario_tag + 0x14)
  40.            
  41.             vehicles_count = read_dword(scenario_data + 0x24C)
  42.             vehicles_data = read_dword(scenario_data + 0x250)
  43.             size = 48
  44.         end
  45.        
  46.         for j=0,vehicles_count-1 do
  47.             local vehicle_metaid = read_dword(vehicles_data + j*size + 0xC)
  48.             if(vehicle_metaid ~= 0xFFFFFFFF) then
  49.                 local vehicle_tag = lookup_tag(vehicle_metaid)
  50.                 local vehicle_data = read_dword(vehicle_tag + 0x14)
  51.                
  52.                 local seats_count = read_dword(vehicle_data + 0x2E4)
  53.                 local seats_data = read_dword(vehicle_data + 0x2E8)
  54.                 for k=0,seats_count-1 do
  55.                     if(read_bit(seats_data + k*284, 2) == 1) then -- if driver seat
  56.                         if(not ALLOW_DRIVER_SEAT) then
  57.                             write_string(seats_data + k*284 + 0x4, "Perhaps This Isn't A Valid Label")
  58.                         end
  59.                     elseif(read_bit(seats_data + k*284, 3) == 1) then -- if gunner seat
  60.                         if(not ALLOW_GUNNER_SEAT) then
  61.                             write_string(seats_data + k*284 + 0x4, "Perhaps This Isn't A Valid Label")
  62.                         end
  63.                        
  64.                         if(DRIVER_REQUIRED_FOR_GUNNER) then
  65.                             write_bit(seats_data + k*284 + 0x1, 1, 1) -- enables 'not valid without driver' flag
  66.                         end
  67.                     else -- if not driver and/or gunner seat assumed to be passenger seat
  68.                         if(not ALLOW_PASSENGER_SEAT) then
  69.                             write_string(seats_data + k*284 + 0x4, "Perhaps This Isn't A Valid Label")
  70.                         end
  71.                        
  72.                         if(DRIVER_REQUIRED_FOR_PASSENGERS) then
  73.                             write_bit(seats_data + k*284 + 0x1, 1, 1) -- enables 'not valid without driver' flag
  74.                         end
  75.                     end
  76.                 end
  77.             end
  78.         end
  79.     end
  80. end
  81.  
  82. function OnTick()
  83.     for i=1,16 do
  84.         if(player_alive(i)) then
  85.             local player = get_dynamic_player(i)
  86.             local player_vehicle_objectid = read_dword(player + 0x11C)
  87.             if(player_vehicle_objectid ~= 0xFFFFFFFF) then
  88.                 local vehicle = get_object_memory(player_vehicle_objectid)
  89.                 local master_objectid = read_dword(vehicle + 0x324)
  90.                 local player_objectid = read_dword(get_player(i) + 0x34)
  91.                 if(master_objectid == player_objectid and read_byte(player + 0x2A3) == 27) then
  92.                     for j=1,16 do
  93.                         if(j ~= i and player_alive(j)) then
  94.                             local other_player = get_dynamic_player(j)
  95.                             local other_player_vehicle_objectid = read_dword(other_player + 0x11C)
  96.                             if(other_player_vehicle_objectid == player_vehicle_objectid and read_byte(other_player + 0x2A3) ~= 27) then
  97.                                 exit_vehicle(j)
  98.                             end
  99.                         end
  100.                     end
  101.                 elseif(master_objectid == 0xFFFFFFFF and read_byte(player + 0x2A3) ~= 27) then
  102.                     exit_vehicle(i)
  103.                 end
  104.             end
  105.         end
  106.     end
  107. end
  108.  
  109. function OnScriptUnload() end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top