Untitled

 avatar
unknown
lua
a year ago
2.6 kB
7
Indexable
local effects = {
    [1] = {
        fromPosition = Position(1078, 434, 7), 
        toPosition = Position(1097, 453, 7), 
        centerPosition = Position(1089, 446, 7), 
        effect = CONST_ME_FIREAREA
    },
}

local intervalTime = 2000
local damageDelay = 1000

local parsedPositions = {}

local function positionToString(position)
    return string.format("%d:%d:%d", position.x, position.y, position.z)
end

local rebirthBossRoom = GlobalEvent("rebirthBoss")
function rebirthBossRoom.onThink(interval)

    for i = 1, #effects do

        local settings = effects[i]
        local fromPosition = settings.fromPosition
        local toPosition = settings.toPosition
        local centerPosition = settings.centerPosition
        local spectators = Game.getSpectators(centerPosition, false, true, 15, 15, 10, 10)

        if #spectators > 0 and settings.effect then

            for _ = 1, 150 do 

                local randomX = math.random(fromPosition.x, toPosition.x)
                local randomY = math.random(fromPosition.y, toPosition.y)

                local newPosition = Position(randomX, randomY, fromPosition.z)
                local positionFormated = positionToString(newPosition)

                if not parsedPositions[positionFormated] then

                    local tile = Tile(newPosition)
                    if tile and tile:isWalkable() and 
                        not tile:tile:hasFlag(TILESTATE_PROTECTIONZONE) and not tile:tile:hasFlag(TILESTATE_HOUSE) then

                        local tileCreatureId = 0
                        local tileCreature = player:getTopCreature()

                        if tileCreature and tileCreature:isPlayer() then
                            tileCreatureId = tileCreature:getId()
                        end

                        newPosition:sendMagicEffect(227)

                        addEvent(
                            function(targetId)

                                local target = Player(targetId)
                                if target then
                                    doTargetCombatHealth(0, playerCheck, COMBAT_FIREDAMAGE, -500, -1000, settings.effect)
                                end
                                
                                newPosition:sendMagicEffect(settings.effect)

                            end,
                            damageDelay, tileCreatureId
                        )

                    end

                    parsedPositions[positionFormated] = 1
                end
            end
        end
    end

    return true
end

rebirthBossRoom:interval(intervalTime)
rebirthBossRoom:register()
Editor is loading...
Leave a Comment