Advertisement
HR_Shaft

Vehicle Leap & Emergency Brake for SAPP

Jun 28th, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.80 KB | None | 0 0
  1. --[[ ###  Vehicle Leap & Emergency Brake 1.0 ###]]--
  2. --[[ ###         by H® Shaft for SAPP        ###]]--
  3.  
  4. -- Allows drivers to activate a vehicle leap (brake key/space bar) and will notify them by message: Vehicle Leap Activated!
  5. -- Allows drivers to activate an emergency brake (crouch key) and will notify them by message: Emergency Brake Activated! this halts forward/reverse and lateral movement
  6. -- Editable parameters allow admins to enable/disable leap/brake per-map, and velocity of the leap
  7. -- Emergency Brake: Can cause the appearance of a lag twich if crouch is pressed and held down, but does not cause any lag whatsoever
  8. -- Supports all stock maps for Halo PC/CE, and you can add your own to the tables below, and should be added to all 3 tables
  9. -- Designed for movable ground vehicles only! Does not work properly for flying vehicles
  10.  
  11. -- If the boolean is true for the map then vehicle leap will be enabled for the map, activated by brake key (space bar)
  12. -- Enable/Disable Leap Table: ensure each line separated by a comma between each line
  13. enable_vehicle_leap = {
  14.     beavercreek         =       false,
  15.     bloodgulch          =       true,
  16.     boardingaction      =       true,
  17.     carousel            =       false,
  18.     chillout            =       false,
  19.     damnation           =       false,
  20.     dangercanyon        =       true,
  21.     deathisland         =       true,
  22.     gephyrophobia       =       true,
  23.     hangemhigh          =       false,
  24.     icefields           =       true,
  25.     infinity            =       true,
  26.     longest             =       false,
  27.     prisoner            =       false,
  28.     putput              =       false,
  29.     ratrace             =       false,
  30.     sidewinder          =       true,
  31.     timberland          =       true,
  32.     wizard              =       false,
  33. }
  34.  
  35. -- Specify the upward leap velocity value for each map that you want
  36. -- Leap Velocity Table: ensure each line separated by a comma between each line
  37. vehicle_velocity = {
  38.     beavercreek         =       0,
  39.     bloodgulch          =       1.85,
  40.     boardingaction      =       0,
  41.     carousel            =       0,
  42.     chillout            =       0,
  43.     damnation           =       0,
  44.     dangercanyon        =       1.65,
  45.     deathisland         =       1.8,
  46.     gephyrophobia       =       1.9,
  47.     hangemhigh          =       0,
  48.     icefields           =       1.8,
  49.     infinity            =       1.85,
  50.     longest             =       0,
  51.     prisoner            =       0,
  52.     putput              =       0,
  53.     ratrace             =       0,
  54.     sidewinder          =       2.2,
  55.     timberland          =       1.8,
  56.     wizard              =       0,
  57. }
  58.  
  59. -- Specify if you want emergency brake enabled each map, activated by crouch key
  60. -- Enable/Disable Brake Table: ensure each line separated by a comma between each line
  61. emergency_brake = {
  62.     beavercreek         =       false,
  63.     bloodgulch          =       true,
  64.     boardingaction      =       false,
  65.     carousel            =       false,
  66.     chillout            =       false,
  67.     damnation           =       false,
  68.     dangercanyon        =       true,
  69.     deathisland         =       true,
  70.     gephyrophobia       =       true,
  71.     hangemhigh          =       false,
  72.     icefields           =       true,
  73.     infinity            =       true,
  74.     longest             =       false,
  75.     prisoner            =       false,
  76.     putput              =       false,
  77.     ratrace             =       false,
  78.     sidewinder          =       true,
  79.     timberland          =       true,
  80.     wizard              =       false,
  81. }
  82.  
  83. --Note: if your map name has spaces, comma, hyphen, brackets, parenthesis or periods, try enclosing the 'map name' like ["this"] in the above tables:
  84. --Example: ["Classic Coagulation"] = value,
  85.  
  86. -- SAPP api version --
  87. api_version = "1.8.0.0"
  88.  
  89. -- do not touch --
  90. brakes = {}
  91. jumps = {}
  92.  
  93. function OnScriptLoad()
  94.     register_callback(cb['EVENT_TICK'],"OnTick")
  95.     register_callback(cb['EVENT_JOIN'],"OnPlayerJoin")
  96.     register_callback(cb['EVENT_LEAVE'],"OnPlayerLeave")
  97.     register_callback(cb['EVENT_GAME_START'],"NewGame")
  98. end
  99.  
  100. function OnScriptUnload()
  101. end
  102.  
  103. function NewGame()
  104.     map = get_var(1,"$map") or "unknown"
  105.     local mapname = map
  106.     enable_vehicle_leap[mapname] = enable_vehicle_leap[mapname] or false
  107.     vehicle_velocity[mapname] = vehicle_velocity[mapname] or 0
  108.     emergency_brake[mapname] = emergency_brake[mapname] or false
  109. end
  110.            
  111. function OnTick()
  112.     local mapname = map
  113.     for i=1,16 do
  114.         local player_dyn = get_dynamic_player(i)
  115.         if (player_dyn ~= 0) then
  116.             local vehicle_objectid = read_dword(player_dyn + 0x11C)
  117.             local vehicle_object = get_object_memory(vehicle_objectid)             
  118.             if (vehicle_object ~= 0) then
  119.                 if PlayerIsDriver(i) then
  120.                     if brakes[i] > 0 then brakes[i] = brakes[i] - 1 end
  121.                     if jumps[i] > 0 then jumps[i] = jumps[i] - 1 end
  122.                     if enable_vehicle_leap[mapname] then
  123.                         -- activated on brake key/space bar
  124.                         if (jumps[i] == 0) and (read_bit(player_dyn + 0x208, 1) == 1) then
  125.                             local vel = (vehicle_velocity[mapname] / 10)
  126.                             jumps[i] = math.floor(4*30)                    
  127.                             say(i, "Vehicle Leap Activated!")
  128.                             write_bit(vehicle_object + 0x10, 5, 1)
  129.                             write_float(vehicle_object + 0x70, vel)        
  130.                         end
  131.                     end
  132.                     if emergency_brake[mapname] then
  133.                         -- activated on crouch key
  134.                         if (brakes[i] == 0) and (bit.band(read_dword(player_dyn + 0x208),7) == 1) then
  135.                             brakes[i] = math.floor(1.5*30)
  136.                             say(i, "Emergency Brake Activated!")
  137.                             write_float(vehicle_object + 0x68, read_float(vehicle_object + 0x68)*0.05)
  138.                             write_float(vehicle_object + 0x6C, read_float(vehicle_object + 0x6C)*0.05)             
  139.                         end
  140.                     end
  141.                 end
  142.             end
  143.         end
  144.     end
  145. end
  146.  
  147. function OnPlayerJoin(PlayerIndex)
  148.     if player_present(PlayerIndex) then
  149.         brakes[PlayerIndex] = 0
  150.         jumps[PlayerIndex] = 0 
  151.     end
  152. end
  153.  
  154. function OnPlayerLeave(PlayerIndex)
  155.     if player_present(PlayerIndex) then
  156.         brakes[PlayerIndex] = nil
  157.         jumps[PlayerIndex] = nil   
  158.     end
  159. end
  160.  
  161. -- Thanks to 002 for this piece:
  162. function PlayerIsDriver(PlayerIndex)
  163.     if (player_present(PlayerIndex) == false) then return false end
  164.     local player_object = get_dynamic_player(PlayerIndex)
  165.     local player_object_id = read_dword(get_player(PlayerIndex) + 0x34)
  166.     local vehicleId = read_dword(player_object + 0x11C)
  167.     if (vehicleId == 0xFFFFFFFF) then return false end
  168.     local obj_id = get_object_memory(vehicleId)
  169.     return read_dword(obj_id + 0x324) == player_object_id
  170. end
  171.  
  172. -- Created by H® Shaft
  173. -- Visit http://halorace.org
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement