Advertisement
HR_Shaft

Random Team and FFA Colors for Sapp

Feb 2nd, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.32 KB | None | 0 0
  1. -- Random Team and FFA Colors
  2. -- by H® Shaft for SAPP
  3.  
  4. -- Team Games: Each game, team colors are randomly selected, and are never the same game to game
  5. -- FFA Games: Each time a player spawns, they are given a new random color
  6. -- inspired by 002's custom colors script
  7.  
  8. api_version = "1.9.0.0"
  9. game_started = false
  10. team_play = false
  11.  
  12. function OnScriptLoad()
  13.     location_store = sig_scan("741F8B482085C9750C")
  14.     if(location_store == 0) then
  15.         location_store = sig_scan("EB1F8B482085C9750C")
  16.         if(location_store == 0) then
  17.             cprint("Failed to find color assignment signature")
  18.         end
  19.     end
  20.    
  21.     safe_write(true)
  22.     write_char(location_store,235)
  23.     safe_write(false)
  24.    
  25.     register_callback(cb['EVENT_JOIN'], "OnPlayerJoin")
  26.     register_callback(cb['EVENT_TEAM_SWITCH'], "ChangeColor")
  27.     register_callback(cb['EVENT_GAME_START'], "OnNewGame")
  28.     register_callback(cb['EVENT_GAME_END'],"OnGameEnd")
  29.     register_callback(cb['EVENT_DIE'], "OnPlayerDie")
  30.  
  31.     if get_var(0, "$gt") ~= "n/a" then
  32.         OnNewGame()    
  33.     end
  34. end
  35.  
  36. function OnNewGame()
  37.     game_started = true
  38.     team_play = getteamplay()
  39.     LoadColors()   
  40. end
  41.  
  42. function OnGameEnd()
  43.     game_started = false
  44. end
  45.  
  46. function OnPlayerJoin(PlayerIndex)
  47.     if (game_started == true) then
  48.         ChangeColor(PlayerIndex)
  49.     end        
  50. end
  51.  
  52. function OnPlayerDie(PlayerIndex, KillerIndex)
  53.     if (game_started == true) then
  54.         if (team_play == false) then
  55.             ChangeColor(PlayerIndex)
  56.         end
  57.     end
  58. end
  59.  
  60. function ChangeColor(PlayerIndex)
  61.     if (game_started == true) then     
  62.         if (player_present(PlayerIndex) == true) then
  63.             if (team_play == true) then
  64.                 if (get_var(PlayerIndex,"$team") == "red") then
  65.                     write_word(get_player(PlayerIndex) + 0x60, contrast_table[random_colors][1])
  66.                 else
  67.                     write_word(get_player(PlayerIndex) + 0x60, contrast_table[random_colors][2])
  68.                 end    
  69.             else
  70.                 local color = rand(1, #SKITTLES+1)
  71.                 write_word(get_player(PlayerIndex) + 0x60, color)  
  72.             end
  73.         end
  74.     end
  75. end
  76.  
  77. function getteamplay()
  78.     if get_var(0,"$ffa") == "0" then
  79.         return true
  80.     else
  81.         return false
  82.     end
  83. end
  84.  
  85. -- 0 = white, 1 = black, 2 = red, 3 = blue, 4 = gray, 5 = yellow, 6 = green
  86. -- 7 = pink, 8 = purple, 9 = cyan, 10 = cobalt, 11 = orange, 12 = teal, 13 = sage,
  87. -- 14 = brown, 15 = tan, 16 = maroon, 17 = salmon
  88. -- skittles: no dank colors: no gray, brown, tan
  89. function LoadColors()
  90.     contrast_table = {}
  91.     contrast_table[1] = {0,1}
  92.     contrast_table[2] = {2,3}
  93.     contrast_table[3] = {5,6}
  94.     contrast_table[4] = {7,8}
  95.     contrast_table[5] = {9,13}
  96.     contrast_table[6] = {10,11}
  97.     contrast_table[7] = {11,1}
  98.     contrast_table[8] = {6,11}
  99.     contrast_table[9] = {16,12}
  100.     contrast_table[10] = {16,10}
  101.     contrast_table[11] = {10,7}
  102.     contrast_table[12] = {8,1}
  103.     contrast_table[13] = {12,8}
  104.     contrast_table[14] = {13,5}
  105.     contrast_table[15] = {5,0}
  106.     contrast_table[16] = {7,6}
  107.     contrast_table[17] = {8,9}
  108.     contrast_table[18] = {13,3}
  109.     contrast_table[19] = {6,10}
  110.     contrast_table[20] = {5,1}
  111.     contrast_table[21] = {2,9}
  112.     random_colors = rand(1, #contrast_table+1)
  113.     SKITTLES = {2,3,5,6,7,8,9,10,11,12,13,17,0}
  114. end
  115.  
  116. function OnScriptUnload()
  117.     if(location_store == 0) then return end
  118.     safe_write(true)
  119.     write_char(location_store,116)
  120.     safe_write(false)  
  121. end
  122.    
  123. -- Created by H® Shaft
  124. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement