daily pastebin goal
18%
SHARE
TWEET

Color Reservation

Chalwk77 Jan 20th, 2019 (edited) 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2. --=====================================================================================================--
  3. Script Name: Color Reservation, for SAPP (PC & CE)
  4. Description: Reserve spartan armor colors for VIP members (based on hash)
  5.  
  6. * Implementing Lua API version 1.11.0.0 (works fine on the latest version: 1.12.0.0)
  7. * NOTE: This mod will only work on NON team based game modes!
  8.  
  9. Copyright (c) 2019, Jericho Crosby <jericho.crosby227@gmail.com>
  10. * Notice: You can use this document subject to the following conditions:
  11. https://github.com/Chalwk77/Halo-Scripts-Phasor-V2-/blob/master/LICENSE
  12.  
  13. * Written by Jericho Crosby (Chalwk)
  14. --=====================================================================================================--
  15. ]]--
  16.  
  17. api_version = "1.11.0.0"
  18. color_table = {}
  19. bool = {}
  20.  
  21. -- Configuration [starts] [!] DO NOT TOUCH THE "Color ID"
  22. --             Color ID     Hash
  23. color_table[1] = {0,        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}  -- white (both of these hashes will trigger white)
  24. color_table[2] = {1,        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- black
  25. color_table[3] = {2,        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- red
  26. color_table[4] = {3,        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- blue
  27. color_table[5] = {4,        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- gray
  28. color_table[6] = {5,        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- yellow
  29. color_table[7] = {6,        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- green
  30. color_table[8] = {7,        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- pink
  31. color_table[9] = {8,        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- purple
  32. color_table[10] = {9,       "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- cyan
  33. color_table[11] = {10,      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- cobalt
  34. color_table[12] = {11,      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- orange
  35. color_table[13] = {12,      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- teal
  36. color_table[14] = {13,      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- sage
  37. color_table[15] = {14,      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- brown
  38. color_table[16] = {15,      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- tan
  39. color_table[17] = {16,      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- maroon
  40. color_table[18] = {17,      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}    -- salmon
  41. -- Note: Make sure you encapsulate hashes in quotes and separate entries with a comma!
  42. -- Like so: color_table[1] = {0, "player hash 1", "player hash 2"}
  43. -- Configuration [ends] -----------------------------------------------------------------
  44.  
  45. function OnScriptLoad()
  46.     register_callback(cb['EVENT_GAME_START'], "OnNewGame")
  47. end
  48.  
  49. function OnScriptUnload()
  50.  
  51. end
  52.  
  53. function OnNewGame()
  54.     if (get_var(1, "$gt") == "slayer") then
  55.         -- Check if team based game
  56.         if not getTeamPlay() then
  57.             register_callback(cb['EVENT_JOIN'], "OnPlayerConnect")
  58.             register_callback(cb['EVENT_SPAWN'], "OnPlayerSpawn")
  59.         else
  60.             cprint("[!] Warning: Color Reservation doesn't support Team Play!", 4+8)
  61.         end
  62.     else
  63.         cprint("[!] Warning: Color Reservation doesn't support " .. get_var(0, "$gt") .. "!", 4+8)
  64.     end
  65. end
  66.  
  67. function OnPlayerConnect(PlayerIndex)
  68.     local hash = getHash(PlayerIndex)
  69.     local player = getPlayer(PlayerIndex)
  70.     for k, v in ipairs(color_table) do
  71.         for i = 1, #v do
  72.             if not string.find(v[i], tostring(hash)) then
  73.                 -- Check if their color is TEAL | if TRUE then set new color (Shoo's color reservation)
  74.                 if (read_byte(player + 0x60) == 12) then
  75.                     bool[PlayerIndex] = true
  76.                     setColor(PlayerIndex, nil, true, hash)
  77.                 end
  78.             else
  79.                 -- player's hash IS LISTED in the color table | execute: setColor()
  80.                 setColor(PlayerIndex, nil, false, hash)
  81.             end
  82.         end
  83.     end
  84. end
  85.  
  86. function OnPlayerSpawn(PlayerIndex)
  87.     if (bool[PlayerIndex] == true) then
  88.         bool[PlayerIndex] = false
  89.         local player_object = read_dword(get_player(PlayerIndex) + 0x34)
  90.         destroy_object(player_object)
  91.     end
  92. end
  93.  
  94. function setColor(PlayerIndex, ColorID, param, hash)
  95.     -- Set this player's color to something random (EXCLUDING TEAL)
  96.     local player = getPlayer(PlayerIndex)
  97.     if (param == true) then
  98.         write_byte(player + 0x60, tonumber(selectRandomColor(12)))
  99.     else
  100.         -- iterate over the entire array and set the appropriate color according to table index
  101.         local color
  102.         for k,v in pairs(color_table) do
  103.             for i = 1, #v do
  104.                 if string.find(v[i], tostring(hash)) then
  105.                     write_byte(player + 0x60, tonumber(v[1]))
  106.                     bool[PlayerIndex] = true
  107.                 end
  108.             end
  109.         end
  110.     end
  111. end
  112.  
  113. function selectRandomColor(exclude)
  114.     math.randomseed(os.time())
  115.     math.random(); math.random(); math.random()
  116.     local num = math.random(0, 17)
  117.     -- If the number selected is equal to the value of "exclude", repeat.
  118.     if num == tonumber(exclude) then
  119.         selectRandomColor(exclude)
  120.     else
  121.         return num
  122.     end
  123. end
  124.  
  125. function getPlayer(PlayerIndex)
  126.     if tonumber(PlayerIndex) then
  127.         if tonumber(PlayerIndex) ~= 0 then
  128.             local player = get_player(PlayerIndex)
  129.             if player ~= 0 then
  130.                 return player
  131.             end
  132.         end
  133.     end
  134.     return nil
  135. end
  136.  
  137. function getHash(PlayerIndex)
  138.     if PlayerIndex ~= nil and PlayerIndex ~= "-1" then
  139.         local hash = get_var(PlayerIndex, "$hash")
  140.         return hash
  141.     end
  142.     return nil
  143. end
  144.  
  145. function getTeamPlay()
  146.     -- Game Mode is team based.
  147.     if (get_var(0, "$ffa") == "0") then
  148.         return true
  149.     else
  150.         -- Game Mode is NOT team based.
  151.         return false
  152.     end
  153. end
  154.  
  155. function OnError(Message)
  156.     print(debug.traceback())
  157. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top