kimokimo
Kimo
Here's something i made for my server, 100% like real tibia anomaly fight.
Add this to your global.lua
And this to lib/core/position.lua
Lua:
local anomalyConfig = {
playerPositions = { --Player Lever Positions
Position(930, 999, 7),
Position(930, 1000, 7),
Position(930, 1001, 7),
Position(930, 1002, 7)
},
sparkPos = {
Position(922, 1000, 7),
Position(927, 1000, 7),
Position(922, 1005, 7),
Position(927, 1005, 7),
Position(924, 1003, 7)
},
hpEvents = {75, 55, 25, 5}, --Health percent boss transform at
anomaly = "anomaly",
charged = "charged anomaly",
sparks = "spark of destruction",
dischargePortal = 25550, --Portal id for the portal that damage the charged anomaly
cdStor = 2324, --Player Cooldown Storage
masterStor = 29757,
anomalyRespawn = Position(924, 1002, 7), --Where boss respawn every time
arena = {
from = Position(921, 998, 7),
to = Position(928, 1005, 7),
center = Position(924, 1002, 7)
},
newPos = Position(928, 1001, 7), --Players enter position
kickPos = Position(930, 1005, 7), --Players kick position
timeOut = 30, --Minutes before getting kicked out
arenaDimensions = {5, 7} -- How wide the arena is [1] == x , [2] == y
}
local function itemRespawn(pos)
local tile = Tile(pos)
local portal = tile:getItemById(anomalyConfig.dischargePortal)
local stor = Game.getStorageValue(anomalyConfig.masterStor)
local randomPos = Position(math.random(anomalyConfig.arena.from.x, anomalyConfig.arena.to.x), math.random(anomalyConfig.arena.from.y, anomalyConfig.arena.to.y), anomalyConfig.arena.from.z)
if portal then
if stor and stor > 0 then
portal:transform(25549)
Game.createItem(anomalyConfig.dischargePortal, 1, randomPos)
addEvent(itemRespawn, 10000, randomPos)
else
portal:transform(25549)
end
end
end
function reset_Anomaly_Arena()
for i = 0, 2 do
Game.setStorageValue(anomalyConfig.masterStor + i, nil)
end
for index, player in ipairs(getPlayers(anomalyConfig.arena.center, anomalyConfig.arenaDimensions[1], anomalyConfig.arenaDimensions[2])) do
player:teleportTo(anomalyConfig.kickPos)
player:say("Your time is out, you got teleported outside the anomaly pit.", TALKTYPE_MONSTER_SAY, false, player, player:getPosition())
end
for index, monster in ipairs(getMonsters(false, anomalyConfig.arena.center, anomalyConfig.arenaDimensions[1], anomalyConfig.arenaDimensions[2])) do
if index > 0 then
monster:remove()
end
end
end
local lever = Action()
function lever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local players = {}
local masterPos = player:getPosition()
if Position(masterPos.x, masterPos.y, masterPos.z) ~= anomalyConfig.playerPositions[1] then
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return false
end
for index, entity in ipairs(getPlayers(anomalyConfig.arena.center, anomalyConfig.arenaDimensions[1], anomalyConfig.arenaDimensions[2])) do
if index > 0 then
player:say("Room is occupied by another team please wait.", TALKTYPE_MONSTER_SAY, false, player, player:getPosition())
end
return false
end
for _, position in ipairs(anomalyConfig.playerPositions) do
local topPlayer = Tile(position):getTopCreature()
if topPlayer and not topPlayer:isPlayer() then
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return false
end
players[#players + 1] = topPlayer
end
reset_Anomaly_Arena()
Game.setStorageValue(anomalyConfig.masterStor, 1)
Game.setStorageValue(anomalyConfig.masterStor + 1, os.time() + anomalyConfig.timeOut * 60)
Game.createMonster(anomalyConfig.anomaly, anomalyConfig.anomalyRespawn)
for i, targetPlayer in ipairs(players) do
targetPlayer:teleportTo(anomalyConfig.newPos, false)
targetPlayer:getPosition():sendMagicEffect(CONST_ME_ENERGYAREA)
targetPlayer:say("You have ".. anomalyConfig.timeOut .." minutes to defeat anomaly and leave the room.", TALKTYPE_MONSTER_SAY, false, targetPlayer, targetPlayer:getPosition())
end
return true
end
lever:aid(28757)
lever:register()
local anomalyHealth = CreatureEvent('Anomaly_Health_Change')
anomalyHealth:type('healthchange')
function anomalyHealth.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType)
local health = (creature:getHealth() / creature:getMaxHealth()) * 100
local change = anomalyConfig.hpEvents[Game.getStorageValue(anomalyConfig.masterStor)]
local randomPos = Position(math.random(anomalyConfig.arena.from.x, anomalyConfig.arena.to.x), math.random(anomalyConfig.arena.from.y, anomalyConfig.arena.to.y), anomalyConfig.arena.from.z)
if Game.getStorageValue(anomalyConfig.masterStor) and Game.getStorageValue(anomalyConfig.masterStor) > 0 then
if change then
if health <= change then
Game.setStorageValue(anomalyConfig.masterStor, Game.getStorageValue(anomalyConfig.masterStor) + 1)
Game.setStorageValue(anomalyConfig.masterStor + 2, creature:getHealth())
creature:remove()
Game.createMonster(anomalyConfig.charged, anomalyConfig.anomalyRespawn)
Game.createItem(anomalyConfig.dischargePortal, 1, randomPos)
addEvent(itemRespawn, 10000, randomPos)
end
end
end
return primaryDamage, primaryType, -secondaryDamage, secondaryType
end
anomalyHealth:register()
local damageTp = MoveEvent()
function damageTp.onStepIn(creature, item, position, fromPosition)
if creature:isMonster() then
if creature:getName():lower() == anomalyConfig.charged then
if creature:getHealth() - 5000 <= 0 then
creature:getPosition():sendAnimatedNumber(5000, TEXTCOLOR_LIGHTBLUE)
creature:getPosition():sendMagicEffect(12)
item:transform(25549)
creature:remove()
local anomalyRes = Game.createMonster(anomalyConfig.anomaly, anomalyConfig.anomalyRespawn)
anomalyRes:setHealth(Game.getStorageValue(anomalyConfig.masterStor + 2))
for i = 1, #anomalyConfig.sparkPos do
Game.createMonster(anomalyConfig.sparks, anomalyConfig.sparkPos[i])
end
else
creature:getPosition():sendAnimatedNumber(5000, TEXTCOLOR_LIGHTBLUE)
creature:getPosition():sendMagicEffect(12)
creature:addHealth(-5000)
end
end
elseif creature:isPlayer() then
doTargetCombatHealth(0, creature, COMBAT_ENERGYDAMAGE, -50, -50, 12)
end
return true
end
damageTp:id(anomalyConfig.dischargePortal)
damageTp:register()
Add this to your global.lua
Lua:
function getPlayers(center, x, y)
local t = {}
local spectator = Game.getSpectators(center, false, false, x, x, y, y)
for i = 1, #spectator do
if spectator[i]:isPlayer() then
table.insert(t, spectator[i])
end
end
return t
end
function getMonsters(name, center, x, y)
local m = {}
local spectator = Game.getSpectators(center, false, false, x, x, y, y)
for i = 1, #spectator do
if spectator[i]:isMonster() then
if name then
if string.find(spectator[i]:getName():lower(), name:lower()) then
table.insert(m, spectator[i])
end
else
table.insert(m, spectator[i])
end
end
end
return m
end
Lua:
function Position.sendAnimatedNumber(self, number, color)
local specs = Game.getSpectators(self, false, true, 9, 9, 8, 8)
if #specs > 0 then
for i = 1, #specs do
local player = specs[i]
player:sendTextMessage(MESSAGE_DAMAGE_DEALT, nil, self, number, color)
end
end
end
Last edited: