local c = {
tp = { x = 1035, y = 895, z = 9 }, -- Change XXXX to the location you want.
text = {
pos = { x = 1035, y = 895, z = 9 },
say = "Prepare for round "
},
area = {
from = { x = 1031, y = 891,z = 9 }, -- the first north-west tile pos
to = { x = 1039, y = 898, z = 9 } -- the last south-east tile pos
},
monsterSpawnPoints = {
[1] = { x = 1032, y = 892, z = 9 }, -- spawn point 1
[2] = { x = 1037, y = 897, z = 9 }, -- spawn point 1
[3] = { x = 1038, y = 892, z = 9 }, -- spawn point 1
[4] = { x = 1032, y = 898, z = 9 } -- spawn point 1
},
rounds = {
[1] = { -- round 1
[1] = { name = "morgaroth" }, -- will spawn at spawn point 1
[2] = { name = "ghazbaran" }, -- will spawn at spawn point 2
[3] = { name = "apocalypse" }, -- will spawn at spawn point 3
[4] = { name = "zugurosh" } -- will spawn at spawn point 4
},
[2] = { -- round 2
[1] = { name = "morgaroth" },
[2] = { name = "ghazbaran" },
[3] = { name = "cobra" },
[4] = { name = "cobra" }
}
},
textColor = 6,
creatures = {},
storage = 10000, -- change this to an unused storage value
SpawnTime = 5 -- how much time should you wait to spawn the creatures in seconds
}
-- since we only have 2 rounds setup this will be the max
local maxRounds = #c.rounds
function spawnCreatures(c, round)
for point, creature in ipairs(c.rounds[round]) do
-- summon the creatures and store the cid of each one summoned
c.creatures[point] = doSummonCreature(creature.name, c.monsterSpawnPoints[point])
end
end
function countCreatures(c)
local count = 0
-- incase we haven't summoned any monsters yet
if #c.creatures < 1 then
return count, true
end
for i in ipairs(c.creatures) do
-- make sure all the creatures are monsters
if isMonster(c.creatures[i]) then
-- and if they are within range or the area, if they are count them
if isInRange(getCreaturePosition(c.creatures[i]), c.area.from, c.area.to) then
count = count + 1
end
else
-- what is the value of c.creatures[i] in the console
print(c.creatures[i])
end
end
-- return amount of creatures
return count, (count == 0)
end
function doAnimatedAllText(pos, text, color)
local textTable = {}
text:gsub("[0-9a-zA-Z]+", function(str) table.insert(textTable, str) end)
for i in ipairs(textTable) do
addEvent(doSendAnimatedText, i * 1000, pos, textTable[i], color)
end
end
function initiate(cid, c, round)
doTeleportThing(cid, c.tp)
doAnimatedAllText(c.text.pos, c.text.say..round, c.textColor)
addEvent(spawnCreatures, c.SpawnTime * 1000, c, round)
end
function onUse(cid, item, frompos, item2, topos)
--local round = ( getPlayerStorageValue(cid, c.storage) <= 0 ) and 1 or getPlayerStorageValue(cid, c.storage)
local round = 1 -- we will fix this later
if(item.itemid == 1946 or item.itemid == 1945) then
doTransformItem(item.uid, (item.itemid == 1946) and item.itemid - 1 or item.itemid + 1) -- transform the switch
local creatureCount, summonCreature = countCreatures(c)
if summonCreature and round ~= maxRounds then
initiate(cid, c, round)
setPlayerStorageValue(cid, c.storage, round + 1)
else
doTransformItem(item.uid, (item.itemid == 1945) and item.itemid + 1 or item.itemid - 1) -- transform the switch back
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, "..getPlayerName(cid).." but there are still "..creatureCount.." creature(s) left to kill.")
end
end
return true
end