Advertisement
HR_Shaft

Auto Vehicle Flip for SAPP, by Giraffe

Sep 2nd, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. -- Auto Vehicle Flip
  2. -- by Giraffe
  3.  
  4. -- This script disables rider ejection (forcing players to exit vehicle when vehicle is upside down)
  5. -- and automatically flips upside down vehicles right-side up.
  6.  
  7. -- true or false, whether or not to only auto flip vehicles that players are in
  8. PLAYER_VEHICLES_ONLY = true
  9.  
  10. -- true or false, whether or not to wait until impact before auto flipping vehicle
  11. WAIT_FOR_IMPACT = true
  12.  
  13. --don't edit below--
  14. api_version = "1.9.0.0"
  15. object_table_ptr = nil
  16. rider_ejection = nil
  17.  
  18. function OnScriptLoad()
  19.     object_table_ptr = sig_scan("8B0D????????8B513425FFFF00008D")
  20.     register_callback(cb['EVENT_TICK'],"OnTick")
  21.     if (halo_type == "CE") then
  22.         rider_ejection = read_byte(0x59A34C)
  23.         write_byte(0x59A34C, 0)
  24.     else
  25.         rider_ejection = read_byte(0x6163EC)
  26.         write_byte(0x6163EC, 0)
  27.     end
  28. end
  29.  
  30. function OnTick()
  31.     if(PLAYER_VEHICLES_ONLY) then
  32.         for i=1,16 do
  33.             if(player_alive(i)) then
  34.                  local player = get_dynamic_player(i)
  35.                  local player_vehicle_id = read_dword(player + 0x11C)
  36.                  if(player_vehicle_id ~= 0xFFFFFFFF) then
  37.                      local vehicle = get_object_memory(player_vehicle_id)
  38.                      flip_vehicle(vehicle)
  39.                  end
  40.             end
  41.         end
  42.     else
  43.         local object_table = read_dword(read_dword(object_table_ptr + 2))
  44.         local object_count = read_word(object_table + 0x2E)
  45.         local first_object = read_dword(object_table + 0x34)
  46.         for i=0,object_count-1 do
  47.             local object = read_dword(first_object + i * 0xC + 0x8)
  48.             if(object ~= 0 and object ~= 0xFFFFFFFF) then
  49.                 if(read_word(object + 0xB4) == 1) then
  50.                     flip_vehicle(object)
  51.                 end
  52.             end
  53.         end
  54.     end
  55. end
  56.  
  57. function flip_vehicle(Object)
  58.     if(read_bit(Object + 0x8B, 7) == 1) then
  59.         if(WAIT_FOR_IMPACT and read_bit(Object + 0x10, 1) == 0) then
  60.             return
  61.         end
  62.         write_vector3d(Object + 0x80, 0, 0, 1)
  63.     end
  64. end
  65.  
  66. function OnScriptUnload()
  67.     if( halo_type == "CE") then
  68.         write_byte(0x59A34C, rider_ejection)
  69.     else
  70.         write_byte(0x6163EC, rider_ejection)
  71.     end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement