Advertisement
HR_Shaft

Block Objective Holders from Driving/Gunning for SAPP

Dec 27th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.51 KB | None | 0 0
  1. -- Block Objective Holders from Driving/Gunning for SAPP
  2. -- by H® Shaft
  3.  
  4. -- Script will eject Flag & Oddball (skull) holders (objective holders) if they enter driver or gunner seat of a vehicle
  5. -- Game-Type editable options allow you to control how it behaves in CTF vs. Odd ball
  6.  
  7. -- Addresses these issues:
  8. -- Oddball/Skull holders: players who enter a driver or gunner seat do not gain time when in these seats: eject them
  9. -- CTF: Flag holders sometimes get in driver/gunner seat and then don't return to their base to score: eject them
  10.     -- Pro: enforces team-effort and individual efforts are more difficult
  11.     -- Con: Makes it difficult for an individual to get away with flag:
  12.     -- Con Solution: increase DELAY_TIME to 7-15 seconds (default = 2.5) to give them a head start to escape enemy area
  13.        
  14. -- Should the script eject flag/oddball holders if they enter the DRIVER seat?
  15. -- true = eject, false = don't eject
  16. EJECT_DRIVER = true
  17.  
  18. -- Should the script eject flag/oddball holders if they enter the GUNNER seat?
  19. -- true = eject, false = don't eject
  20. EJECT_GUNNER = true
  21.  
  22. -- What game-types should this be applied to?
  23. -- 1 = CTF game-type only
  24. -- 2 = Oddball game-type only
  25. -- 3 = Both CTF and Oddball game-types
  26. APPLY_TO = 3
  27.  
  28. -- Amount of time (in seconds) to delay before ejecting flag/oddball holders if entering driver/gunner seat
  29. -- MINIMUM DELAY_TIME = 2.5 seconds  (this is the fastest a player can be ejected)
  30. -- The longer the delay time, the longer the player remains in the driver/gunner seat
  31. DELAY_TIME = 2.5
  32.  
  33. -- end configuration
  34. api_version = "1.9.0.0"
  35.  
  36. function OnScriptLoad()
  37.     register_callback(cb['EVENT_VEHICLE_ENTER'], "OnVehicleEnter")
  38. end
  39.  
  40. function OnVehicleEnter(PlayerIndex, Seat)
  41.     local seat = tonumber(Seat)
  42.     local gametype = get_var(0, "$gt")
  43.     if (APPLY_TO == nil) then return end
  44.     if (DELAY_TIME == nil) or (DELAY_TIME < 2.5) then DELAY_TIME = 2.5 end
  45.     -- both CTF and Oddball
  46.     if (APPLY_TO == 3) then
  47.         if (gametype == "ctf") or (gametype == "oddball") then
  48.             if (seat == 0) then
  49.                 if (Has_Objective(PlayerIndex) == true) then
  50.                     if (EJECT_DRIVER == true) then 
  51.                         timer(DELAY_TIME * 1000, "Eject_Holder", PlayerIndex, seat)
  52.                     end
  53.                 end
  54.             elseif (seat == 2) then
  55.                 if (Has_Objective(PlayerIndex) == true) then
  56.                     if (EJECT_DRIVER == true) then
  57.                         timer(DELAY_TIME * 1000, "Eject_Holder", PlayerIndex, seat)
  58.                     end
  59.                 end    
  60.             end
  61.         end
  62.     -- CTF only
  63.     elseif (APPLY_TO == 1) then
  64.         if (gametype == "ctf") then
  65.             if (seat == 0) then
  66.                 if (Has_Objective(PlayerIndex) == true) then
  67.                     if (EJECT_DRIVER == true) then 
  68.                         timer(DELAY_TIME * 1000, "Eject_Holder", PlayerIndex, seat)
  69.                     end
  70.                 end
  71.             elseif (seat == 2) then
  72.                 if (Has_Objective(PlayerIndex) == true) then
  73.                     if (EJECT_DRIVER == true) then
  74.                         timer(DELAY_TIME * 1000, "Eject_Holder", PlayerIndex, seat)
  75.                     end
  76.                 end    
  77.             end
  78.         end
  79.     -- Oddball only
  80.     elseif (APPLY_TO == 2) then
  81.         if (gametype == "oddball") then
  82.             if (seat == 0) then
  83.                 if (Has_Objective(PlayerIndex) == true) then
  84.                     if (EJECT_DRIVER == true) then 
  85.                         timer(DELAY_TIME * 1000, "Eject_Holder", PlayerIndex, seat)
  86.                     end
  87.                 end
  88.             elseif (seat == 2) then
  89.                 if (Has_Objective(PlayerIndex) == true) then
  90.                     if (EJECT_DRIVER == true) then
  91.                         timer(DELAY_TIME * 1000, "Eject_Holder", PlayerIndex, seat)
  92.                     end
  93.                 end    
  94.             end
  95.         end
  96.     end    
  97. end
  98.  
  99. function Eject_Holder(PlayerIndex, seat)
  100.     local seat = tonumber(seat)
  101.     if not player_alive(PlayerIndex) then return end
  102.     if isinvehicle(PlayerIndex) and (seat ~= nil) then
  103.         if (seat == 0) then
  104.             exit_vehicle(PlayerIndex)
  105.             say(PlayerIndex, " |*EJECTED!*|  You cannot drive while holding oddball or flag!")
  106.         elseif (seat == 2) then
  107.             exit_vehicle(PlayerIndex)
  108.             say(PlayerIndex, " |*EJECTED!*|  You cannot use gunner seat while holding oddball or flag!")           
  109.         end    
  110.     end    
  111.     return false
  112. end
  113.  
  114. -- iterates thru all players weapons, returns true if they have flag or oddball, if not, returns false
  115. -- this is specifically checking the 'must be readied' flag of each of their weapons
  116. function Has_Objective(PlayerIndex)
  117.     local response = false
  118.     if get_var(0, "$gt") ~= "n/a" then
  119.         if (get_var(0, "$gt") == "ctf") or (get_var(0, "$gt") == "oddball") then
  120.             local player_object = get_dynamic_player(PlayerIndex)
  121.             for w=0,3 do
  122.                 local weap_id = read_dword(player_object + 0x2F8 + 0x4 * w)
  123.                 if (weap_id ~= 0xFFFFFFFF) then
  124.                     local weap_obj = get_object_memory(weap_id)
  125.                     if (weap_obj ~= 0) then
  126.                         local obj_type = read_byte(weap_obj + 0xB4)
  127.                         local tag_address = read_word(weap_obj)
  128.                         local tagdata = read_dword(read_dword(0x40440000) + tag_address * 0x20 + 0x14)
  129.                         if (read_bit(tagdata + 0x308,3) == 1) then
  130.                             response = true
  131.                         end
  132.                     end    
  133.                 end
  134.             end    
  135.         end
  136.     end
  137.     return response
  138. end
  139.  
  140. function isinvehicle(PlayerIndex)
  141.     local player_object = get_dynamic_player(PlayerIndex)
  142.     if player_object ~= 0 then
  143.         local vehicleId = read_dword(player_object + 0x11C)
  144.         if vehicleId == 0xFFFFFFFF then
  145.             return false
  146.         else
  147.             return true
  148.         end
  149.     else
  150.         return false
  151.     end
  152. end
  153.  
  154. function OnScriptUnload() end
  155.  
  156. function OnError(Message)
  157.     print(debug.traceback())
  158. end
  159.  
  160. -- Created by H® Shaft
  161. -- Visit http://halorace.org/forum/index.php
  162.  
  163. -- The player -db-GoNe/Juhleek - a well spoken liar, cheat.
  164. -- -db- is: "diverging from the believable" - How ironic. A race clan where admins use rcon to favor themselves to win.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement