stoneharry

Untitled

Dec 14th, 2011
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None | 0 0
  1.  
  2. local Race_System = {
  3.     RACE_STATUS = "Looking For Racers",
  4.     RACERS = {},
  5.     WON = {},
  6.     LOST = {},
  7.     PAGE = {},
  8.     SHOW = {}
  9. }
  10.  
  11. function PageCounter(page)
  12.     if page == 0 then
  13.         return 1
  14.     else
  15.         return (page*10)+1
  16.     end
  17. end
  18.  
  19. function DisplayRacesWon(id) -- integrate with DB support
  20.     if Race_System.WON[Race_System.RACERS[id]] ~= nil then
  21.         return Race_System.WON[Race_System.RACERS[id]];
  22.     else
  23.         return 0;
  24.     end
  25. end
  26.  
  27. function DisplayRacesLost(id) -- integrate with DB support
  28.     if Race_System.LOST[Race_System.RACERS[id]] ~= nil then
  29.         return Race_System.LOST[Race_System.RACERS[id]];
  30.     else
  31.         return 0;
  32.     end
  33. end
  34.  
  35. function ReturnPageLength(PAGE_COUNTER, TABLE_LENGTH)
  36.     if (TABLE_LENGTH - PAGE_COUNTER) > 10 then
  37.         return PAGE_COUNTER+10;
  38.     else
  39.         return TABLE_LENGTH;
  40.     end
  41. end
  42.  
  43. function Test_Item_Trigger(item, event, player)
  44.     Test_Item(item, player)
  45. end
  46.  
  47. function Test_Item(item, player, intid, code)
  48.     if Race_System.PAGE[player] == nil then
  49.         Race_System.PAGE[player] = 0
  50.     end
  51.    
  52.     item:GossipCreateMenu(50, player, 0)
  53.     if intid ~= nil then
  54.         player:SendBroadcastMessage(intid)
  55.     end
  56.     player:SendBroadcastMessage("[DEBUG] Page: "..Race_System.PAGE[player])
  57.     item:GossipMenuAddItem(0, "|cff3060B5Current status:|r "..Race_System.RACE_STATUS, 1, 0)
  58.     if Race_System.RACE_STATUS == "Looking For Racers" then
  59.         item:GossipMenuAddItem(9, "Sign me up for this race!", 2, 0)
  60.     end
  61.     if #Race_System.RACERS ~= 0 then
  62.         for i = PageCounter(Race_System.PAGE[player]), ReturnPageLength(PageCounter(Race_System.PAGE[player])-1, #Race_System.RACERS) do
  63.             item:GossipMenuAddItem(10, "   > Racer "..i..": "..Race_System.RACERS[i]:GetName(), 100+i, 0)
  64.             if (intid == i+100) and (Race_System.SHOW[intid] == true) then
  65.                 item:GossipMenuAddItem(0, "|cff095F0B     > Races won: |r"..DisplayRacesWon(i), 100+i, 0)
  66.                 item:GossipMenuAddItem(0, "|cFFFF0000     > Races lost: |r"..DisplayRacesLost(i), 100+i, 0)
  67.             end
  68.             if tostring(i/10):find('%.') == nil and #Race_System.RACERS > i then
  69.                 item:GossipMenuAddItem(7, "Next page.", 4, 0)
  70.             end
  71.             if Race_System.PAGE[player] ~= 0 and (i == ReturnPageLength(PageCounter(Race_System.PAGE[player])-1, #Race_System.RACERS)) then
  72.                 item:GossipMenuAddItem(7, "Previous page.", 5, 0)
  73.             end
  74.         end
  75.     end
  76.     item:GossipMenuAddItem(0, "[Exit]", 99, 0)
  77.     item:GossipSendMenu(player)
  78. end
  79.  
  80. function Test_Item_Select(item, event, player, id, intid, code)
  81.     if (intid == 1) then
  82.         Test_Item(item, player)
  83.     end
  84.    
  85.     if (intid == 2) then
  86.         --[[local PLAYER_MATCH = 0 -- using a local variable instead of return otherwise we can't send the menu again, thus
  87.         for k,v in pairs(Race_System.RACERS) do -- we would be stuck with a "broken" menu
  88.             if v == player then
  89.                 PLAYER_MATCH = 1
  90.                 break;
  91.             end
  92.         end
  93.         if PLAYER_MATCH == 0 then--]]
  94.                 table.insert(Race_System.RACERS, player)
  95.         --else
  96.             --player:SendBroadcastMessage("You've already been signed up!")
  97.         --end
  98.         Test_Item(item, player)
  99.     end
  100.    
  101.     if (intid == 4) then
  102.         Race_System.PAGE[player] = Race_System.PAGE[player] + 1
  103.         Test_Item(item, player)
  104.     end
  105.    
  106.     if (intid == 5) then
  107.         Race_System.PAGE[player] = Race_System.PAGE[player] - 1
  108.         Test_Item(item, player)
  109.     end
  110.    
  111.     if (intid == 99) then
  112.         player:GossipComplete()
  113.     end
  114.    
  115.     for i = 101, (#Race_System.RACERS+100) do
  116.         if (intid == i) then
  117.             if Race_System.SHOW[intid] == true then
  118.                 Race_System.SHOW[intid] = false
  119.             else
  120.                 Race_System.SHOW[intid] = true
  121.             end
  122.             Test_Item(item, player, intid)
  123.         end
  124.     end
  125. end
  126.  
  127. RegisterItemGossipEvent(57060, 1, "Test_Item_Trigger")
  128. RegisterItemGossipEvent(57060, 2, "Test_Item_Select")
  129.  
Advertisement
Add Comment
Please, Sign In to add comment