Advertisement
HR_Shaft

Vehicle Fly Mode for SAPP

Apr 8th, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.56 KB | None | 0 0
  1. -- Vehicle Fly Mode by H® Shaft
  2. -- a derivation/re-write of Flymo v0.6 By =GG=DLBon
  3.  
  4. -- This is a script which makes vehicles fly if the space bar/brake is pressed and held by the driver in a vehicle.
  5. -- Fall and distance damage are blocked while a player is in a vehicle
  6. -- works with any vehicle, any map, any gametype in Halo PC/CE   -- NOT tested with stationary turrets
  7.  
  8. -- How fast should a vehicle move up when driver presses space bar/brake? Default = 0.07
  9. movespeed = 0.07
  10.  
  11. -- Do not change anything below
  12. api_version = "1.9.0.0"
  13. currentjump = {}
  14. previousjump = {}
  15. vid = {}
  16. permi = {}
  17.  
  18. function OnScriptLoad()
  19.     register_callback(cb["EVENT_TICK"],"OnTick")
  20.     register_callback(cb['EVENT_SPAWN'],"OnPlayerSpawn")
  21.     register_callback(cb['EVENT_DAMAGE_APPLICATION'], "OnDamageApplication")
  22.     if get_var(0, "$gt") ~= "n/a" then
  23.         GetMetaIDs()
  24.         for i = 1, 16 do
  25.             if player_present(i) then
  26.                 OnPlayerSpawn(i)
  27.             end
  28.         end
  29.     end
  30. end
  31.  
  32. function OnPlayerSpawn(PlayerIndex)
  33.     currentjump[PlayerIndex] = 0
  34.     previousjump[PlayerIndex] = 0
  35.     permi[PlayerIndex] = 0
  36. end
  37.  
  38. function OnTick()
  39.     for PlayerIndex=1,16 do
  40.         if player_alive(PlayerIndex) then
  41.             local player = get_dynamic_player(PlayerIndex)     
  42.             currentjump[PlayerIndex] = read_bit(player + 0x208,1)
  43.             if isinvehicle(PlayerIndex) and PlayerIsDriver(PlayerIndex) then
  44.                 vid[PlayerIndex] = read_bit(player + 0x11C,0)
  45.                 if currentjump[PlayerIndex] == 1 then
  46.                     if get_var(0, "$gt") ~= "race" then
  47.                         if (vid[PlayerIndex] ~= 1) then
  48.                             permi[PlayerIndex] = 1
  49.                         end
  50.                     else
  51.                         if (vid[PlayerIndex] ~= 0) then
  52.                             permi[PlayerIndex] = 1
  53.                         end
  54.                     end    
  55.                 else
  56.                     permi[PlayerIndex] = 0
  57.                 end
  58.             end
  59.             if isinvehicle(PlayerIndex) and PlayerIsDriver(PlayerIndex) then
  60.                 local vehicle_objectid = read_dword(player + 0x11C)
  61.                 local vehicle_object = get_object_memory(vehicle_objectid)                 
  62.                 if permi[PlayerIndex] == 1 then
  63.                     if vehicle_object ~= 0 then
  64.                         write_float(vehicle_object + 0x70, movespeed)
  65.                     end
  66.                 end
  67.                 previousjump[PlayerIndex] = currentjump[PlayerIndex]
  68.             end
  69.         end
  70.     end
  71. end
  72.  
  73. function OnDamageApplication(PlayerIndex, CauserIndex, MetaID, Damage, HitString, Backtap)
  74.     if MetaID == falling_damage then
  75.         if isinvehicle(PlayerIndex) then
  76.             return true, 0
  77.         else
  78.             return true, Damage
  79.         end
  80.     elseif MetaID == distance_damage then
  81.         if isinvehicle(PlayerIndex) then
  82.             return true, 0
  83.         else
  84.             return true, Damage
  85.         end
  86.     end
  87. end    
  88.  
  89. function GetMetaIDs()
  90.     falling_damage = read_dword(lookup_tag("jpt!", "globals\\falling") + 12)
  91.     distance_damage = read_dword(lookup_tag("jpt!", "globals\\distance") + 12)
  92. end
  93.  
  94. function PlayerIsDriver(PlayerIndex)
  95.     if (player_present(PlayerIndex) == false) then return false end
  96.     local player_object = get_dynamic_player(PlayerIndex)
  97.     local player_object_id = read_dword(get_player(PlayerIndex) + 0x34)
  98.     local vehicleId = read_dword(player_object + 0x11C)
  99.     if (vehicleId == 0xFFFFFFFF) then return false end
  100.     local obj_id = get_object_memory(vehicleId)
  101.     return read_dword(obj_id + 0x324) == player_object_id
  102. end
  103.  
  104. function isinvehicle(PlayerIndex)
  105.     if (player_alive(PlayerIndex) == false) then return false end
  106.     local player_object = get_dynamic_player(PlayerIndex)
  107.     local vehicleId = read_dword(player_object + 0x11C)
  108.     if vehicleId == 0xFFFFFFFF then
  109.         return false
  110.     else
  111.         return true
  112.     end
  113. end
  114.  
  115. function OnScriptUnload() end
  116.  
  117. function OnError(Message)
  118.     print(debug.traceback())
  119. end
  120.  
  121. -- Created by H® Shaft
  122. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement