Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Race_System = {
- RACE_STATUS = "Looking For Racers",
- RACERS = {},
- WON = {},
- LOST = {},
- PAGE = {},
- SHOW = {}
- }
- function PageCounter(page)
- if page == 0 then
- return 1
- else
- return (page*10)+1
- end
- end
- function DisplayRacesWon(id) -- integrate with DB support
- if Race_System.WON[Race_System.RACERS[id]] ~= nil then
- return Race_System.WON[Race_System.RACERS[id]];
- else
- return 0;
- end
- end
- function DisplayRacesLost(id) -- integrate with DB support
- if Race_System.LOST[Race_System.RACERS[id]] ~= nil then
- return Race_System.LOST[Race_System.RACERS[id]];
- else
- return 0;
- end
- end
- function ReturnPageLength(PAGE_COUNTER, TABLE_LENGTH)
- if (TABLE_LENGTH - PAGE_COUNTER) > 10 then
- return PAGE_COUNTER+10;
- else
- return TABLE_LENGTH;
- end
- end
- function Test_Item_Trigger(item, event, player)
- Test_Item(item, player)
- end
- function Test_Item(item, player, intid, code)
- if Race_System.PAGE[player] == nil then
- Race_System.PAGE[player] = 0
- end
- item:GossipCreateMenu(50, player, 0)
- if intid ~= nil then
- player:SendBroadcastMessage(intid)
- end
- player:SendBroadcastMessage("[DEBUG] Page: "..Race_System.PAGE[player])
- item:GossipMenuAddItem(0, "|cff3060B5Current status:|r "..Race_System.RACE_STATUS, 1, 0)
- if Race_System.RACE_STATUS == "Looking For Racers" then
- item:GossipMenuAddItem(9, "Sign me up for this race!", 2, 0)
- end
- if #Race_System.RACERS ~= 0 then
- for i = PageCounter(Race_System.PAGE[player]), ReturnPageLength(PageCounter(Race_System.PAGE[player])-1, #Race_System.RACERS) do
- item:GossipMenuAddItem(10, " > Racer "..i..": "..Race_System.RACERS[i]:GetName(), 100+i, 0)
- if (intid == i+100) and (Race_System.SHOW[intid] == true) then
- item:GossipMenuAddItem(0, "|cff095F0B > Races won: |r"..DisplayRacesWon(i), 100+i, 0)
- item:GossipMenuAddItem(0, "|cFFFF0000 > Races lost: |r"..DisplayRacesLost(i), 100+i, 0)
- end
- if tostring(i/10):find('%.') == nil and #Race_System.RACERS > i then
- item:GossipMenuAddItem(7, "Next page.", 4, 0)
- end
- if Race_System.PAGE[player] ~= 0 and (i == ReturnPageLength(PageCounter(Race_System.PAGE[player])-1, #Race_System.RACERS)) then
- item:GossipMenuAddItem(7, "Previous page.", 5, 0)
- end
- end
- end
- item:GossipMenuAddItem(0, "[Exit]", 99, 0)
- item:GossipSendMenu(player)
- end
- function Test_Item_Select(item, event, player, id, intid, code)
- if (intid == 1) then
- Test_Item(item, player)
- end
- if (intid == 2) then
- --[[local PLAYER_MATCH = 0 -- using a local variable instead of return otherwise we can't send the menu again, thus
- for k,v in pairs(Race_System.RACERS) do -- we would be stuck with a "broken" menu
- if v == player then
- PLAYER_MATCH = 1
- break;
- end
- end
- if PLAYER_MATCH == 0 then--]]
- table.insert(Race_System.RACERS, player)
- --else
- --player:SendBroadcastMessage("You've already been signed up!")
- --end
- Test_Item(item, player)
- end
- if (intid == 4) then
- Race_System.PAGE[player] = Race_System.PAGE[player] + 1
- Test_Item(item, player)
- end
- if (intid == 5) then
- Race_System.PAGE[player] = Race_System.PAGE[player] - 1
- Test_Item(item, player)
- end
- if (intid == 99) then
- player:GossipComplete()
- end
- for i = 101, (#Race_System.RACERS+100) do
- if (intid == i) then
- if Race_System.SHOW[intid] == true then
- Race_System.SHOW[intid] = false
- else
- Race_System.SHOW[intid] = true
- end
- Test_Item(item, player, intid)
- end
- end
- end
- RegisterItemGossipEvent(57060, 1, "Test_Item_Trigger")
- RegisterItemGossipEvent(57060, 2, "Test_Item_Select")
Advertisement
Add Comment
Please, Sign In to add comment