Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local OBJECT_END = 0x0006
- local UNIT_FIELD_FLAGS = OBJECT_END + 0x0035 -- Size: 1, Type: INT, Flags: PUBLIC
- local Race_System = {
- RACE_STATUS = "Looking For Racers",
- RACERS = {},
- WON = {},
- LOST = {},
- PAGE = {},
- SHOW = {},
- CURRENT = {},
- started = false,
- countdown = 10,
- place = 1,
- RACING = {},
- WINORDER = {},
- print_count = 0,
- counted,
- outputwinners = false
- }
- local VAR = {}
- function PageCounter(page)
- if page == 0 then
- return 1
- else
- return (page*10)+1
- end
- end
- function DisplayRacesWon(name)
- local query = CharDBQuery("SELECT `won` FROM `racestats` WHERE `name` = '"..name.."';")
- if query ~= nil then
- return query:GetColumn(0):GetString()
- else
- return 0
- end
- end
- function DisplayRacesLost(name)
- local query = CharDBQuery("SELECT `lost` FROM `racestats` WHERE `name` = '"..name.."';")
- if query ~= nil then
- return query:GetColumn(0):GetString()
- 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:GetName()] == nil then
- Race_System.PAGE[player:GetName()] = 0
- end
- item:GossipCreateMenu(50, player, 0)
- item:GossipMenuAddItem(4, "|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:GetName()]), ReturnPageLength(PageCounter(Race_System.PAGE[player:GetName()])-1, #Race_System.RACERS) do
- if Race_System.RACERS[i]:GetName() then
- item:GossipMenuAddItem(4, " > Racer "..i..": "..Race_System.RACERS[i]:GetName(), 100+i, 0)
- if (intid == i+100) and (Race_System.SHOW[intid] == true) then
- item:GossipMenuAddItem(4, "|cff095F0B > Races won: |r"..DisplayRacesWon(Race_System.RACERS[i]:GetName()), 100+i, 0)
- item:GossipMenuAddItem(4, "|cFFFF0000 > Races lost: |r"..DisplayRacesLost(Race_System.RACERS[i]:GetName()), 100+i, 0)
- end
- 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:GetName()] ~= 0 and (i == ReturnPageLength(PageCounter(Race_System.PAGE[player:GetName()])-1, #Race_System.RACERS)) then
- item:GossipMenuAddItem(7, "Previous page.", 5, 0)
- end
- end
- end
- item:GossipMenuAddItem(0, "Nevermind.", 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
- for k,v in pairs(Race_System.RACERS) do
- if v:GetName() == player:GetName() 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:GetName()] = Race_System.PAGE[player:GetName()] + 1
- Test_Item(item, player)
- end
- if (intid == 5) then
- Race_System.PAGE[player:GetName()] = Race_System.PAGE[player:GetName()] - 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")
- function CheckIfRaceCanStart()
- if Race_System.RACE_STATUS == "Looking For Racers" then
- if #Race_System.RACERS > 1 then
- local i = 0
- for k,plr in pairs(Race_System.RACERS) do
- if plr == nil then
- --table.remove(Race_System.RACERS, plr) -- bugs script
- elseif plr:GetName() then
- i = i + 1
- end
- end
- if i > 1 then
- local k = 1
- for _,plr in pairs(Race_System.RACERS) do
- if plr ~= nil and plr:GetName() then
- plr:Dismount()
- plr:SetPlayerLock(true)
- plr:Root()
- if k > 5 then
- plr:SetPlayerLock(false)
- plr:Unroot()
- break
- elseif k == 1 then
- plr:Teleport(1, -6204, -3911, -60.32)
- elseif k == 2 then
- plr:Teleport(1, -6204, -3907, -60.32)
- elseif k == 3 then
- plr:Teleport(1, -6204, -3903, -60.32)
- elseif k == 4 then
- plr:Teleport(1, -6202, -3898, -60.32)
- elseif k == 5 then
- plr:Teleport(1, -6204, -3894, -60.32)
- end
- k = k + 1
- table.insert(Race_System.CURRENT, plr)
- end
- end
- RegisterTimedEvent("SetStatusOncePlayersLoaded", 5000, 1)
- -- spawning a vehicle in a timed event = crash
- end
- end
- end
- end
- function SetStatusOncePlayersLoaded()
- Race_System.RACE_STATUS = "Race in progress..."
- end
- RegisterTimedEvent("CheckIfRaceCanStart", 10000, 0)
- function Race_Creature_Handler_Spawn(pUnit, Event)
- pUnit:RegisterEvent("Check_PlayersIfRacing", 1000, 0)
- end
- local countdown = false
- function Check_PlayersIfRacing(pUnit)
- if countdown then
- Race_System.countdown = Race_System.countdown - 1
- if Race_System.countdown < 1 then
- Race_System.countdown = 10
- Race_System.started = true
- countdown = false
- Race_System.counted = true
- pUnit:SendChatMessage(42,0,"GO!")
- for _,plr in pairs(pUnit:GetInRangePlayers()) do
- if plr:IsOnVehicle() then
- plr:Unroot()
- plr:SetPlayerLock(false)
- plr:GetVehicleBase():Unroot()
- end
- end
- elseif Race_System.countdown < 6 then
- pUnit:SendChatMessage(42,0,tostring(Race_System.countdown))
- if Race_System.countdown == 5 then
- for _,plr in pairs(pUnit:GetInRangePlayers()) do
- if plr:IsOnVehicle() then
- local vehicle = plr:GetVehicleBase()
- vehicle:SetPosition(vehicle:GetX(), vehicle:GetY(), vehicle:GetZ()+0.1, vehicle:GetO())
- end
- end
- end
- end
- end
- for _,plr in pairs(pUnit:GetInRangePlayers()) do
- if plr ~= nil then
- if Race_System.RACE_STATUS == "Race in progress..." and not Race_System.counted then
- countdown = true
- if not plr:IsOnVehicle() then
- local name = plr:GetName()
- local istrue = false
- local position = 0
- for k,two in pairs(Race_System.CURRENT) do
- if two:GetName() == name then
- istrue = true
- position = k
- break
- end
- end
- if istrue then
- local query = CharDBQuery("SELECT `vehicle` FROM `racestats` WHERE `name` = '"..name.."';")
- if query == nil then
- CharDBQuery("INSERT INTO `racestats` VALUES ('"..name.."', 0, 0, 33062);")
- query = "33062"
- else
- query = query:GetColumn(0):GetString()
- end
- if tonumber(query) == 33062 then
- plr:SpawnCreature(33775, plr:GetX(), plr:GetY(), plr:GetZ(), plr:GetO(), 35, 0)
- end
- plr:SpawnAndEnterVehicle(tonumber(query), 1000)
- table.remove(Race_System.CURRENT, position)
- table.insert(Race_System.RACING, plr)
- end
- elseif plr:GetVehicleBase():GetEntry() == 33062 and plr:HasEmptyVehicleSeat() then
- local unit = plr:GetCreatureNearestCoords(plr:GetX(), plr:GetY(), plr:GetZ(), 33775)
- if unit ~= nil and not unit:IsOnVehicle() then
- if plr:IsOnVehicle() then
- unit:SetUInt32Value(UNIT_FIELD_FLAGS, 10) -- look like a player
- unit:EnterVehicle(plr:GetVehicleBase(), 1000)
- end
- end
- end
- if not Race_System.started then
- if plr:IsOnVehicle() then
- plr:GetVehicleBase():Root()
- end
- --[[else
- if plr:IsOnVehicle() then
- plr:Unroot()
- plr:SetPlayerLock(false)
- plr:GetVehicleBase():Unroot()
- end]]
- end
- end
- end
- end
- if Race_System.outputwinners then
- Race_System.print_count = #Race_System.WINORDER
- for i = 1, #Race_System.WINORDER do
- pUnit:RegisterEvent("printnamelistorder", 3000 * i, 1)
- end
- Race_System.outputwinners = false
- end
- end
- function printnamelistorder(pUnit, plr)
- local zzplace = nil
- if Race_System.print_count == 5 then
- zzplace = "5th"
- elseif Race_System.print_count == 4 then
- zzplace = "4th"
- elseif Race_System.print_count == 3 then
- zzplace = "3rd"
- elseif Race_System.print_count == 2 then
- zzplace = "2nd"
- elseif Race_System.print_count == 1 then
- zzplace = "1st"
- end
- local plr = Race_System.WINORDER[Race_System.print_count]
- pUnit:SendChatMessage(42,0,plr:GetName().." came in "..zzplace.." place!")
- Race_System.print_count = Race_System.print_count - 1
- if Race_System.print_count == 0 then
- Race_System.print_count = 5
- Race_System.RACE_STATUS = "Looking For Racers"
- for k,v in pairs(Race_System.RACERS) do
- table.remove(Race_System.RACERS, k)
- end
- for k,v in pairs(Race_System.CURRENT) do
- table.remove(Race_System.CURRENT, k)
- end
- Race_System.started = false
- Race_System.countdown = 10
- Race_System.place = 1
- for k,v in pairs(Race_System.RACING) do
- table.remove(Race_System.RACING, k)
- end
- for k,v in pairs(Race_System.WINORDER) do
- table.remove(Race_System.WINORDER, k)
- end
- for k,v in pairs(Race_System.PAGE) do
- table.remove(Race_System.PAGE, k)
- end
- for k,v in pairs(Race_System.SHOW) do
- table.remove(Race_System.SHOW)
- end
- end
- end
- RegisterUnitEvent(33340, 18, "Race_Creature_Handler_Spawn")
- function CheckPointSpawner_Spawned(pUnit, Event)
- pUnit:RegisterEvent("CheckPoint_CheckPlace", 1000, 0)
- end
- function CheckPoint_CheckPlace(pUnit)
- if Race_System.started then
- for _,plr in pairs(pUnit:GetInRangePlayers()) do
- --if plr:IsOnVehicle() then
- if pUnit:GetDistanceYards(plr) < 18 then
- local entry = pUnit:GetEntry()
- local name = plr:GetName()
- Race_System[name] = Race_System[name] or {VAR={}}
- if Race_System[name].VAR.point == nil then
- Race_System[name].VAR.point = 0
- end
- if entry == 88101 and Race_System[name].VAR.point == 0 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 1!", plr)
- Race_System[name].VAR.point = 1
- elseif entry == 88102 and Race_System[name].VAR.point == 1 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 2!", plr)
- Race_System[name].VAR.point = 2
- elseif entry == 88103 and Race_System[name].VAR.point == 2 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 3!", plr)
- Race_System[name].VAR.point = 3
- elseif entry == 88104 and Race_System[name].VAR.point == 3 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 4!", plr)
- Race_System[name].VAR.point = 4
- elseif entry == 88105 and Race_System[name].VAR.point == 4 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 5!", plr)
- Race_System[name].VAR.point = 5
- elseif entry == 88106 and Race_System[name].VAR.point == 5 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 6!", plr)
- Race_System[name].VAR.point = 6
- elseif entry == 88107 and Race_System[name].VAR.point == 6 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 7!", plr)
- Race_System[name].VAR.point = 7
- elseif entry == 88108 and Race_System[name].VAR.point == 7 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 8!", plr)
- Race_System[name].VAR.point = 8
- elseif entry == 88109 and Race_System[name].VAR.point == 8 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 9!", plr)
- Race_System[name].VAR.point = 9
- elseif entry == 88110 and Race_System[name].VAR.point == 9 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 10!", plr)
- Race_System[name].VAR.point = 10
- elseif entry == 88111 and Race_System[name].VAR.point == 10 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 11!", plr)
- Race_System[name].VAR.point = 11
- elseif entry == 88112 and Race_System[name].VAR.point == 11 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 12!", plr)
- Race_System[name].VAR.point = 12
- elseif entry == 88113 and Race_System[name].VAR.point == 12 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have passed checkpoint 13!", plr)
- Race_System[name].VAR.point = 13
- elseif entry == 88114 and Race_System[name].VAR.point == 13 then
- if pUnit:GetDistanceYards(plr) < 5 then
- if Race_System.place == 1 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have come 1st!", plr)
- CharDBQuery("UPDATE `racestats` SET `won` = won + '1' WHERE `name` = '"..plr:GetName().."';")
- elseif Race_System.place == 2 then
- if #Race_System.RACING == 2 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have come last!", plr)
- CharDBQuery("UPDATE `racestats` SET `lost` = lost + '1' WHERE `name` = '"..plr:GetName().."';")
- else
- pUnit:SendChatMessageToPlayer(42, 0, "You have come 2nd!", plr)
- end
- elseif Race_System.place == 3 then
- if #Race_System.RACING == 3 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have come last!", plr)
- CharDBQuery("UPDATE `racestats` SET `lost` = lost + '1' WHERE `name` = '"..plr:GetName().."';")
- else
- pUnit:SendChatMessageToPlayer(42, 0, "You have come 3rd!", plr)
- end
- elseif Race_System.place == 4 then
- if #Race_System.RACING == 4 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have come last!", plr)
- CharDBQuery("UPDATE `racestats` SET `lost` = lost + '1' WHERE `name` = '"..plr:GetName().."';")
- else
- pUnit:SendChatMessageToPlayer(42, 0, "You have come 4th!", plr)
- end
- elseif Race_System.place == 5 then
- pUnit:SendChatMessageToPlayer(42, 0, "You have come last!", plr)
- CharDBQuery("UPDATE `racestats` SET `lost` = lost + '1' WHERE `name` = '"..plr:GetName().."';")
- end
- table.insert(Race_System.WINORDER, plr)
- Race_System.place = Race_System.place + 1
- if #Race_System.WINORDER == #Race_System.RACING then
- pUnit:SendChatMessage(42,0,"All participants have reached the finish line!")
- Race_System.outputwinners = true
- Race_System.RACE_STATUS = "Announcing winners..."
- end
- Race_System[name].VAR.point = 14
- --[[for k,v in pairs(Race_System.RACING) do
- if v == nil then
- table.remove(Race_System.RACING, k)
- elseif v:GetName() == plr:GetName() then
- table.remove(Race_System.RACING, k)
- end
- end]]
- plr:ExitVehicle()
- local query = CharDBQuery("SELECT `vehicle` FROM `racestats` WHERE `name` = '"..name.."';")
- if query ~= nil then
- local vehicle = tonumber(query:GetColumn(0):GetString())
- if vehicle == 33062 then
- plr:GetCreatureNearestCoords(plr:GetX(),plr:GetY(),plr:GetZ(),33775):Despawn(1,0)
- end
- plr:GetCreatureNearestCoords(plr:GetX(),plr:GetY(),plr:GetZ(),vehicle):Despawn(100,0)
- end
- plr:MoveKnockback(-6176.9, -3886.5, -57, 6, 8)
- end
- end
- end
- --end
- end
- end
- end
- for i=1, 14 do
- RegisterUnitEvent(88100+i, 18, "CheckPointSpawner_Spawned")
- end
- function exploiters_go_die()
- if Race_System.started then
- for k,plr in pairs(Race_System.RACING) do
- if plr == nil then
- table.remove(Race_System.RACING, k)
- elseif not plr:IsOnVehicle() then
- local found = false
- for k,v in pairs(Race_System.WINORDER) do
- if v:GetName() == plr:GetName() then
- found = true
- break
- end
- end
- if not found then
- table.remove(Race_System.RACING, k)
- plr:SendBroadcastMessage("You have been removed from the race for cheating!")
- plr:Teleport(0, 0, 0, 0) -- teleport out of the race because they are not on a vehicle (cheating)
- end
- end
- end
- end
- end
- --RegisterTimedEvent("exploiters_go_die", 2500, 0)
Advertisement
Add Comment
Please, Sign In to add comment