Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local players = {}
- local config = {
- teleporter = {{x = 160, y = 54, z = 7}, {x = 227, y = 118, z = 14}}, -- location, destination
- teleportOpenTime = 1000 * 10, -- 1000 * 5 = 5 seconds
- arena_location = {{x = 221, y = 112, z = 14}, {x = 233, y = 124, z = 14}}, -- top_left_corner, bottom_right_corner
- minimum_participants = 2,
- time_between_rounds = 10,
- random_time_for_rounds = {5, 15},
- outfits = {{lookType = 128, lookHead = 79, lookBody = 79, lookLegs = 79, lookFeet = 79}, {lookType = 128, lookHead = 77, lookBody = 77, lookLegs = 77, lookFeet = 77}, {lookType = 128, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94}}
- }
- local function countParticipants()
- local count = 0
- for _ in pairs(players) do count = count + 1 end
- return count
- end
- local function countParticipantsRemaining()
- local count = 0
- for index, index_ in pairs(players) do
- if index_[2] > 0 and index_[2] < 4 then
- count = count + 1
- end
- end
- return count
- end
- local function changeParticipantsOutfits()
- for index, index_ in pairs(players) do
- if isPlayer(index_[1]) then
- if index_[2] < 4 then
- doSetCreatureOutfit(index_[1], config.outfits[index_[2]], -1)
- end
- end
- end
- end
- local function checkEventWinners()
- if countParticipantsRemaining() > 2 then
- addEvent(eventRoundsIdle, 0)
- elseif countParticipantsRemaining() == 1 then
- for index, index_ in pairs(players) do
- if isPlayer(index_[1]) then
- doBroadcastMessage("" .. getCreatureName(index_[1]) .. " won the event!")
- addEvent(doTeleportThing, 5000, index_[1], getTownTemplePosition(getPlayerTown(index_[1])))
- doSetCreatureOutfit(index_[1], index_[3], -1)
- end
- end
- players = {}
- else
- doBroadcastMessage("Nobody won the event! All participants were eliminated.")
- players = {}
- end
- end
- local function checkEventLosers()
- for index, index_ in pairs(players) do
- if isPlayer(index_[1]) then
- if index_[2] == 4 then
- index_[2] = index_[2] + 1
- doTeleportThing(index_[1], getTownTemplePosition(getPlayerTown(index_[1])))
- doSetCreatureOutfit(index_[1], index_[3], -1)
- end
- end
- end
- addEvent(checkEventWinners, 0)
- end
- local function eventRoundsFinish()
- for index, index_ in pairs(players) do
- if isPlayer(index_[1]) then
- if index_[2] < 4 then
- print(index_[2])
- if getTileThingByPos(getThingPosition(index_[1])).itemid == 407 then
- index_[2] = index_[2] + 1
- print(index_[2])
- end
- end
- end
- end
- changeParticipantsOutfits()
- addEvent(checkEventLosers, 0)
- end
- local function eventRoundsStart()
- -- set random tiles
- addEvent(eventRoundsFinish, (math.random(config.random_time_for_rounds[1], config.random_time_for_rounds[2]) * 1000))
- end
- local function eventRoundsIdle()
- addEvent(eventRoundsStart, config.time_between_rounds)
- end
- local function checkParticipants()
- local text = "Players"
- local playerCount = countParticipants()
- if playerCount >= config.minimum_participants then
- for index, index_ in pairs(players) do
- if isPlayer(index_[1]) then
- if text ~= "Players" then
- text = text .. ","
- end
- text = text .. " " .. getCreatureName(index_[1]) .. ""
- end
- end
- text = text .. " have entered the event."
- end
- if text == "Players" then
- doBroadcastMessage("Event cancelled. Not enough participants.")
- if playerCount > 0 then
- for index, index_ in pairs(players) do
- if isPlayer(index_[1]) then
- doTeleportThing(index_[1], getTownTemplePosition(getPlayerTown(index_[1])))
- doSetCreatureOutfit(index_[1], index_[3], -1)
- end
- end
- players = {}
- end
- else
- doBroadcastMessage(text)
- addEvent(doBroadcastMessage, 5000, "Event will start in " .. config.time_between_rounds .. " seconds.")
- changeParticipantsOutfits()
- addEvent(eventRoundsIdle, 5000)
- end
- return
- end
- local function removeTeleporter()
- doRemoveItem(getTileItemById(config.teleporter[1], 1387).uid)
- for _, pid in ipairs(getPlayersOnline()) do
- if isPlayer(pid) then
- local pos = getThingPosition(pid)
- if pos.z <= config.arena_location[1].z and pos.z >= config.arena_location[2].z then
- if pos.x >= config.arena_location[1].x and pos.x <= config.arena_location[2].x then
- if pos.y >= config.arena_location[1].y and pos.y <= config.arena_location[2].y then
- local pid_outfit = getCreatureOutfit(pid)
- players[pid] = {pid, 1, pid_outfit}
- end
- end
- end
- end
- end
- doBroadcastMessage("Starting event..")
- addEvent(checkParticipants, 5000)
- return
- end
- function onTime()
- doCreateTeleport(1387, config.teleporter[2], config.teleporter[1])
- addEvent(removeTeleporter, config.teleportOpenTime)
- doBroadcastMessage("Event in Progress..")
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement