stoneharry

Untitled

May 16th, 2015
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 KB | None | 0 0
  1.  
  2. local CHOICE_TABLE = {
  3.     -- TYPES:
  4.     --      1: Spell
  5.     --      2: Item
  6.     -- Each set of values must contain at least 3 unique values
  7.     -- level = { number of types, type1, set of values for type1, ... }
  8.     [2] = {2, 1, {1752, 1752, 1908}, 2, {50055, 23368, 26029}},
  9.     [3] = {2, 1, {1752, 1752, 1908}, 2, {50055, 23368, 26029}},
  10.     [4] = {2, 1, {1752, 1752, 1908}, 2, {50055, 23368, 26029}},
  11.     [5] = {2, 1, {1752, 1752, 1908}, 2, {50055, 23368, 26029}},
  12.     [6] = {2, 1, {1752, 1752, 1908}, 2, {50055, 23368, 26029}}
  13.    
  14. }
  15.  
  16. local function PLAYER_EVENT_ON_LEVEL_CHANGE(event, player, oldLevel)
  17.     local t = CHOICE_TABLE[oldLevel + 1]
  18.     if not t then
  19.         return
  20.     end
  21.     local numTypes = t[1];
  22.     local results = {}
  23.     for i=1,3 do
  24.         local _type = math.random(1, t[1])
  25.         local values = t[(_type * 2) + 1]
  26.         local inserted = false
  27.         while not inserted do
  28.             local val = values[math.random(1, #values)]
  29.             local valid = true
  30.             for _,v in pairs(results) do
  31.                 if (v[1] == _type and v[2] == val) then
  32.                     valid = false
  33.                 end
  34.             end
  35.             if valid then
  36.                 table.insert(results, {_type, val})
  37.                 inserted = true
  38.             end
  39.         end
  40.     end
  41.    
  42.     local message = "LEVELUP-" .. string.format("%02d", oldLevel + 1)
  43.     for i=1,3 do
  44.         message = message .. "-" ..  string.format("%01d", results[i][1])
  45.         message = message .. "-" ..  string.format("%06d", results[i][2])
  46.     end
  47.    
  48.     sendAddonMessage(player, message, 1)
  49. end
  50.  
  51. RegisterPlayerEvent(13, PLAYER_EVENT_ON_LEVEL_CHANGE)
Advertisement
Add Comment
Please, Sign In to add comment