Advertisement
HR_Shaft

Alternating Camo for Sapp

Jun 9th, 2017
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.36 KB | None | 0 0
  1. -- Alternating Camo for Sapp by H® Shaft
  2.  
  3. -- If enabled, players will have alternating camouflage randomly lasting between 2 and 6 seconds, followed by 6 seconds of visibility
  4. -- You can enable or disable for each map, and - you can add your own maps see line 117: alternating_camo table of function SetDefaults()
  5. -- This will not affect the typical 30 seconds of invisibility a player gets when picking up the active camouflage
  6.  
  7. -- Sapp Version 10 changed the duration of camo to be multiplied by 30 = 1 second, previous versions were multiplied by 1000 = 1 second
  8. -- if you are using an older version of sapp than 1.10.0.0 - set OLD_VERSION to true
  9. -- Sehe the author of sapp, was not around to verify which specific version he made this change - so, experiment if needed.
  10. OLD_VERSION = false
  11.  
  12. api_version = "1.10.0.0"
  13.  
  14. function OnScriptLoad()
  15.     register_callback(cb['EVENT_GAME_START'], "OnNewGame")
  16.     register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
  17.     register_callback(cb['EVENT_SPAWN'], "OnPlayerSpawn")
  18.     if get_var(0, "$gt") ~= "n/a" then
  19.         game_started = true
  20.         OnNewGame()
  21.     else
  22.         game_started = false
  23.     end
  24. end
  25.  
  26. function OnScriptUnload()
  27.     alternating_camo = {}
  28. end
  29.  
  30. function OnNewGame()
  31.     game_started = true
  32.     map_name = get_var(0,"$map")
  33.     SetDefaults()  
  34. end
  35.  
  36. function OnGameEnd()
  37.     game_started = false
  38. end
  39.  
  40. function OnPlayerSpawn(PlayerIndex)
  41.     if player_present(PlayerIndex) then
  42.         if (alternating_camo[map_name] == true) then -- if enabled ...
  43.             local random_start = rand(1, 6) -- between 1 and 5 seconds to start
  44.             local start = (random_start * 1000)
  45.             randomcamo = timer(start, "Random_Camo", PlayerIndex) -- begin first loop
  46.         end
  47.     end
  48. end
  49.  
  50. function Random_Camo(PlayerIndex)
  51.     if player_present(PlayerIndex) and game_started then
  52.         local invis = tonumber(get_var(PlayerIndex, "$invis")) -- 1 if camo'd, 0 if not or dead
  53.         local random_duration = rand(2, 7) -- between 2 and 6 seconds in duration
  54.         local duration
  55.         if not OLD_VERSION then
  56.             duration = (random_duration * 30)
  57.         else
  58.             duration = (random_duration * 1000)
  59.         end
  60.         local start = (random_duration * 1000 + 8000)
  61.         if invis == 0 and player_alive(PlayerIndex) then
  62.             camo(PlayerIndex, duration)
  63.             reapplycamo = timer(start, "Reapply_Camo", PlayerIndex) -- continue the loop
  64.         else
  65.             reapplycamo = timer(start, "Reapply_Camo", PlayerIndex) -- continue the loop
  66.         end
  67.     end
  68.     return false
  69. end
  70.  
  71. function Reapply_Camo(PlayerIndex)
  72.     if player_present(PlayerIndex) and game_started then
  73.         local invis = tonumber(get_var(PlayerIndex, "$invis")) -- 1 if camo'd, 0 if not or dead
  74.         local random_duration = rand(2, 7) -- between 2 and 6 seconds in duration
  75.         local duration
  76.         if not OLD_VERSION then
  77.             duration = (random_duration * 30)
  78.         else
  79.             duration = (random_duration * 1000)
  80.         end
  81.         local start = (random_duration * 1000 + 8000)
  82.         if invis == 0 and player_alive(PlayerIndex) then
  83.             camo(PlayerIndex, duration)
  84.             randomcamo = timer(start, "Random_Camo", PlayerIndex) -- restart the loop +1 second later
  85.         else
  86.             recyclecamo = timer(start, "Recycle_Camo", PlayerIndex) -- continue the loop a bit later, player is either dead or still has camo
  87.         end
  88.     end
  89.     return false
  90. end
  91.  
  92. function Recycle_Camo(PlayerIndex)
  93.     if player_present(PlayerIndex) and game_started then
  94.         local invis = tonumber(get_var(PlayerIndex, "$invis")) -- 1 if camo'd, 0 if not or dead
  95.         local random_duration = rand(2, 7) -- between 2 and 6 seconds in duration
  96.         local duration
  97.         if not OLD_VERSION then
  98.             duration = (random_duration * 30)
  99.         else
  100.             duration = (random_duration * 1000)
  101.         end
  102.         local start = (random_duration * 1000 + 8000)
  103.         if invis == 0 and player_alive(PlayerIndex) then
  104.             camo(PlayerIndex, duration)
  105.             randomcamo = timer(start, "Random_Camo", PlayerIndex) -- restart the loop +1 second later
  106.         else
  107.             randomcamo = timer(start, "Random_Camo", PlayerIndex) -- continue the loop a bit later, player is either dead or still has camo
  108.         end        
  109.     end
  110.     return false
  111. end
  112.  
  113.  
  114. function SetDefaults()
  115.    
  116.     -- EDIT HERE: enabled = true, disabled = false You can add your own maps, but be sure to separate each entry with a comma as seen below
  117.     alternating_camo = {
  118.         ["bloodgulch"]          =       true,
  119.         ["dangercanyon"]        =       true,
  120.         ["deathisland"]         =       true,
  121.         ["gephyrophobia"]       =       true,
  122.         ["icefields"]           =       true,
  123.         ["infinity"]            =       true,
  124.         ["sidewinder"]          =       true,
  125.         ["timberland"]          =       true,
  126.         ["hangemhigh"]          =       true,
  127.         ["ratrace"]             =       true,
  128.         ["beavercreek"]         =       true,
  129.         ["damnation"]           =       true,
  130.         ["boardingaction"]      =       true,
  131.         ["carousel"]            =       true,
  132.         ["putput"]              =       true,
  133.         ["prisoner"]            =       true,
  134.         ["wizard"]              =       true,
  135.     }
  136.    
  137.     -- don't edit below this -- restart if script is reloaded during a game
  138.     for i=1,16 do
  139.         if player_alive(i) then
  140.             if alternating_camo[map_name] == true and game_started then
  141.                 local invis = tonumber(get_var(i, "$invis"))
  142.                 local random_start = rand(1, 6) -- between 1 and 5 seconds to start
  143.                 local start = (random_start * 1000)            
  144.                 if invis == 0 then
  145.                     randomcamo = timer(start, "Random_Camo", i)
  146.                 end
  147.             end
  148.         end
  149.     end    
  150.    
  151. end
  152.  
  153. -- Created by H® Shaft
  154. -- Visit http://halorace.org/forum/index.php
  155.  
  156. -- The player -db-GoNe/Juhleek - a well spoken liar, cheat.
  157. -- -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