HR_Shaft

Race Guardian v1 for Phasor v2

Mar 30th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.21 KB | None | 0 0
  1. --[[ ###  Race Guardian  ###]]--
  2. --[[ ###   by H® Shaft   ###]]--
  3.  
  4. -- Race Guardian: Will warn, then damage and/or kill those who are not racing in a vehicle.  If a player is killed by this script, it will say so.
  5. -- Damage will stop when the player enters a vehicle, and the timer begins again when they exit the vehicle or when they respawn.
  6. -- Suggestion: Use in conjuction with my Taxi script: http://pastebin.com/EYqiMWU4
  7.  
  8. -- Edit --
  9. timeout_time = 10   --| time in seconds - Amount of time given after warning before damage begins. Suggested Time Out Time: 10 seconds
  10. max_time = 60       --| time in seconds - Amount of time allowed to be on foot before being warned to get in a vehicle  Suggested Max Time: 60 seconds
  11.  
  12. -- Don't Edit --
  13. warned = {}
  14. foot_time = {}
  15. last_damage = {}
  16. enable_guardian = {}
  17.  
  18. -- If the boolean is true for the map then Race Guardian will be enabled for the map
  19. --                  Map:                        Boolean:
  20. enable_guardian.    beavercreek         =       false       -- battle creek
  21. enable_guardian.    bloodgulch          =       true
  22. enable_guardian.    boardingaction      =       false              
  23. enable_guardian.    carousel            =       false       -- derelict
  24. enable_guardian.    chillout            =       false              
  25. enable_guardian.    damnation           =       false              
  26. enable_guardian.    dangercanyon        =       true               
  27. enable_guardian.    deathisland         =       true           
  28. enable_guardian.    gephyrophobia       =       true               
  29. enable_guardian.    hangemhigh          =       false              
  30. enable_guardian.    icefields           =       true               
  31. enable_guardian.    infinity            =       true               
  32. enable_guardian.    longest             =       false              
  33. enable_guardian.    prisoner            =       false              
  34. enable_guardian.    putput              =       false       -- chiron tl34
  35. enable_guardian.    ratrace             =       false              
  36. enable_guardian.    sidewinder          =       true               
  37. enable_guardian.    timberland          =       true               
  38. enable_guardian.    wizard              =       false
  39.  
  40.  
  41. function GetRequiredVersion()
  42.     return 200
  43. end
  44.  
  45. function OnScriptLoad(process, game, persistent)
  46.     if game == true or game == "PC" then
  47.         GAME = "PC"
  48.         Map = readstring(0x698F21)
  49.     else
  50.         GAME = "CE"
  51.         Map = readstring(0x61D151)
  52.     end
  53.     GAME = game
  54.     for i=0,15 do
  55.         if getplayer(i) then
  56.             foot_time[i], warned[gethash(i)] = 0, nil
  57.         end
  58.     end
  59. end
  60.  
  61. function OnNewGame(map)
  62.     if GAME == "PC" then
  63.         Map = readstring(0x698F21)
  64.     else
  65.         Map = readstring(0x61D151)
  66.     end
  67.     for i=0,15 do
  68.         if getplayer(i) then
  69.             foot_time[i], warned[gethash(i)] = 0, nil
  70.         end
  71.     end
  72.     if enable_guardian[Map] then
  73.         timer = registertimer(1000, "Timer")
  74.     end    
  75. end
  76. function OnScriptUnload()
  77.     if timer then
  78.         removetimer(timer)
  79.         timer = nil
  80.     end
  81.     if timeout then
  82.         removetimer(timeout)
  83.         timeout = nil
  84.     end
  85. end
  86.  
  87. function OnPlayerJoin(player)
  88.     if getplayer(player) then
  89.         foot_time[player] = 0
  90.         warned[gethash(player)] = nil
  91.         announce = registertimer(6000, "timedannounce", player)
  92.     end
  93. end
  94.  
  95. function OnPlayerSpawn(player, m_objectId)
  96.     if getplayer(player) then
  97.         foot_time[player] = 0
  98.         warned[gethash(player)] = nil
  99.     end
  100. end
  101.  
  102. function OnPlayerSpawnEnd(player, m_objectId)
  103.     if getplayer(player) then
  104.         last_damage[gethash(player)] = nil
  105.     end
  106. end
  107.  
  108. function OnPlayerLeave(player)
  109.     if getplayer(player) then
  110.         warned[gethash(player)] = nil
  111.     end
  112. end
  113.  
  114. function Timeout(id, count)
  115.     for i = 0,15 do
  116.         if getplayer(i) and warned[gethash(i)] then
  117.             warned[gethash(i)] = nil
  118.         end
  119.     end
  120.     return false
  121. end
  122.  
  123. function Timer(id, count)
  124.     for i=0,15 do
  125.         if getplayer(i) then
  126.             local m_objectId = getplayerobjectid(i)
  127.             if m_objectId and not isinvehicle(i) then
  128.                 foot_time[i] = (foot_time[i] or 0) + 1
  129.             else
  130.                 foot_time[i] = 0
  131.             end            
  132.             if m_objectId and not isinvehicle(i) and warned[gethash(i)] and foot_time[i] > (max_time + timeout_time) then
  133.                 applydmgtag(m_objectId, gettagid("jpt!", "vehicles\\scorpion\\bullet"), 1, m_objectId) -- m_objectId is causer, can also be 0xFFFFFFFF which causes no death message in onplayerkill
  134.             elseif m_objectId and isinvehicle(i) and warned[gethash(i)] then
  135.                 foot_time[i] = 0
  136.                 warned[gethash(i)] = nil
  137.             elseif m_objectId and not isinvehicle(i) and warned[gethash(i)] == nil and foot_time[i] > max_time then
  138.                 warn = registertimer(timeout_time * 1000, "Warn", i)
  139.             end
  140.         end
  141.     end
  142.     return true
  143. end
  144.  
  145. function Warn(id, count, player)
  146.     if count == 1 then
  147.         if getplayer(player) and warned[gethash(player)] == nil and not isinvehicle(player) then
  148.             local name = getname(player)
  149.             warned[gethash(player)] = true
  150.             foot_time[player] = foot_time[player] - timeout_time
  151.             sendconsoletext(player, name .. ": Get in a vehicle immediately and race, or face death.")
  152.             sendconsoletext(player, "You have " .. timeout_time .. " seconds(s) to comply.")
  153.             timeout = registertimer(timeout_time * 1000, "Timeout")
  154.         end
  155.     end
  156.     return false
  157. end
  158.  
  159. function OnVehicleEntry(player, m_vehicleId, seat, mapId, relevant)
  160.     if getplayer(player) then
  161.         foot_time[player] = 0
  162.         warned[gethash(player)] = nil
  163.     end
  164.     return nil
  165. end
  166.  
  167. function OnDamageApplication(receiving, causing, tagid, hit, backtap)
  168.     if receiving then
  169.         local r_object = getobject(receiving)
  170.         if r_object then
  171.             local receiver = objectaddrtoplayer(r_object)
  172.             if receiver then
  173.                 local r_hash = gethash(receiver)
  174.                 local tagname,tagtype = gettaginfo(tagid)
  175.                 last_damage[r_hash] = tagname
  176.             end
  177.         end
  178.     end
  179. end
  180.  
  181. function OnPlayerKill(killer, victim, mode)
  182.     local response = false
  183.     if mode == 6 and last_damage[gethash(victim)] == "vehicles\\scorpion\\bullet" then
  184.         response = false
  185.         say(getname(victim) .. " was killed by the guardians for not racing in a vehicle.")
  186.         return response
  187.     end
  188. end
  189.  
  190. function timedannounce(id, count, player)
  191.     if getplayer(player) then
  192.         if enable_guardian[Map] then sendconsoletext(player, "Race Guardian is Enabled.") end
  193.     end
  194.     return false   
  195. end
  196.  
  197. function OnGameEnd(stage)
  198.     if stage == 1 then 
  199.         if timer then
  200.             removetimer(timer)
  201.             timer = nil
  202.         end
  203.         if timeout then
  204.             removetimer(timeout)
  205.             timeout = nil
  206.         end
  207.         if warn then
  208.             removetimer(warn)
  209.             warn = nil
  210.         end
  211.         if announce then
  212.             removetimer(announce)
  213.             announce = nil
  214.         end        
  215.     end
  216. end
  217.  
  218. -- Created by H® Shaft thank you to Oxide, AelitePrime, Nugget & Wizard.
  219. -- Visit http://halorace.org/forum/index.php?topic=514.0 or
  220. -- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
Advertisement
Add Comment
Please, Sign In to add comment