• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

RevScripts Boss with Enraged and Tiles Deal Damage

Belfahar

New Member
Joined
Jul 21, 2016
Messages
25
Reaction score
3
Good evening! I am creating a boss with a mechanic where, when it reaches 90% HP, it gains a 25% damage buff (this already works using onThink). And an event is triggered where random tiles are generated within the room that deal 5K damage to the player stepping on them (this works using onStepIn, but I need to record the ID of the tile).

The issue is that when I register the tile ID, all other tiles with the same ID scattered across the map also deal 5K damage.

Lua:
local bossName = "Goshnar's Greed"
local floorId = 410
local replacementFloorId = 429
local floorCount = 4
local fromPos = {x = 4853, y = 4323, z = 15}
local toPos = {x = 4864, y = 4334, z = 15}
local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
condition:setParameter(CONDITION_PARAM_SUBID, 88888)
condition:setParameter(CONDITION_PARAM_TICKS, -1)
condition:setParameter(CONDITION_PARAM_BUFF_DAMAGEDEALT, 125)

local function replaceFloorsWithNewId(floors)
    for _, pos in ipairs(floors) do
        local tile = Tile(pos)
        if tile then
            local item = tile:getItemById(floorId)
            if item then
                item:transform(replacementFloorId)
            end
        end
    end
end

local function createRandomFloors()
    local randomFloors = {}
    for i = 1, floorCount do
        local randomX = math.random(fromPos.x, toPos.x)
        local randomY = math.random(fromPos.y, toPos.y)
        local randomZ = math.random(fromPos.z, toPos.z)
        table.insert(randomFloors, {x = randomX, y = randomY, z = randomZ})
        local newItem = Game.createItem(floorId, 1, {x = randomX, y = randomY, z = randomZ})
    end
    return randomFloors
end

local function removeFloors(floors)
    for _, pos in ipairs(floors) do
        local tile = Tile(pos)
        if tile then
            local item = tile:getItemById(floorId)
            if item then
                item:remove()
            end
        end
    end
end

local GreedTile = MoveEvent()
function GreedTile.onStepIn(creature, item, position, fromPosition, toPosition, isHotkey)
    local itemId = item:getId()
    if itemId == floorId then
        doTargetCombatHealth(0, creature, COMBAT_FIREDAMAGE, -5000, -5000, CONST_ME_HITBYFIRE)
   end
end

local GreedBerserk = CreatureEvent("GreedBerserk")
function GreedBerserk.onThink(creature)
    local hp = (creature:getHealth() / creature:getMaxHealth()) * 100
    if hp < 90 and not creature:getCondition(CONDITION_PARAM_BUFF_DAMAGEDEALT, CONDITIONID_DEFAULT, 88888) then
        local randomFloors = createRandomFloors()   
        addEvent(replaceFloorsWithNewId, 10 * 1000, randomFloors)
        creature:addCondition(condition)
    end

    addEvent(function(cid)
        local creature = Creature(cid)
        if not creature then
            return
        end

        creature:addHealth(500)

        return true
    end, 4000, creature:getId())
end

GreedBerserk:register()
GreedTile:id(410)
GreedTile:register()
 
Solution
Good evening! I am creating a boss with a mechanic where, when it reaches 90% HP, it gains a 25% damage buff (this already works using onThink). And an event is triggered where random tiles are generated within the room that deal 5K damage to the player stepping on them (this works using onStepIn, but I need to record the ID of the tile).

The issue is that when I register the tile ID, all other tiles with the same ID scattered across the map also deal 5K damage.

Lua:
local bossName = "Goshnar's Greed"
local floorId = 410
local replacementFloorId = 429
local floorCount = 4
local fromPos = {x = 4853, y = 4323, z = 15}
local toPos = {x = 4864, y = 4334, z = 15}
local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)...
Best solution is to use an action ID on the tiles that you want the damage to apply to. Then you just use RME to set the action ids on the tiles themselves.

Lua:
local GreedTile = MoveEvent()
function GreedTile.onStepIn(creature, item, position, fromPosition, toPosition, isHotkey)
    doTargetCombatHealth(0, creature, COMBAT_FIREDAMAGE, -5000, -5000, CONST_ME_HITBYFIRE)
end

GreedTile:aid(5000)
GreedTile:register()

Or, you can just add a position check within the same function, and compare your position within a range (from -> to)
 
You cannot register multiple callbacks in a single event, you must create two instances and register your callbacks in each of them.
Lua:
local config = {
    bossName = "Goshnar's Greed",
    floorId = 410,
    replacementFloorId = 429,
    floorCount = 4,
    fromPos = {x = 4853, y = 4323, z = 15},
    toPos = {x = 4864, y = 4334, z = 15},
}

local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
condition:setParameter(CONDITION_PARAM_SUBID, 88888)
condition:setParameter(CONDITION_PARAM_TICKS, -1)
condition:setParameter(CONDITION_PARAM_BUFF_DAMAGEDEALT, 125)

local function replaceFloorsWithNewId(floors, oldId, newId)
    for _, pos in ipairs(floors) do
        local tile = Tile(pos)
        if tile then
            local item = tile:getItemById(oldId)
            if item then
                item:transform(newId)
            end
        end
    end
end

local function createRandomFloors()
    local randomFloors = {}
    for i = 1, config.floorCount do
        local randomX = math.random(config.fromPos.x, config.toPos.x)
        local randomY = math.random(config.fromPos.y, config.toPos.y)
        local randomZ = math.random(config.fromPos.z, config.toPos.z)
        table.insert(randomFloors, {x = randomX, y = randomY, z = randomZ})
        local newItem = Game.createItem(config.floorId, 1, {x = randomX, y = randomY, z = randomZ})
    end
    return randomFloors
end

local GreedTileStepIn = MoveEvent()

function GreedTileStepIn.onStepIn(creature, item, position, fromPosition, toPosition, isHotkey)
    if item:getId() == config.floorId then
        doTargetCombatHealth(0, creature, COMBAT_FIREDAMAGE, -5000, -5000, CONST_ME_HITBYFIRE)
    end
end

GreedTileStepIn:id(config.floorId)
GreedTileStepIn:register()

local GreedBerserkThink = CreatureEvent("GreedBerserk")

function GreedBerserkThink.onThink(creature)
    local hp = (creature:getHealth() / creature:getMaxHealth()) * 100
    if hp < 90 and not creature:getCondition(CONDITION_PARAM_BUFF_DAMAGEDEALT, CONDITIONID_DEFAULT, 88888) then
        local randomFloors = createRandomFloors()   
        addEvent(replaceFloorsWithNewId, 10 * 1000, randomFloors, config.floorId, config.replacementFloorId)
        creature:addCondition(condition)
    end

    addEvent(function(cid)
        local creature = Creature(cid)
        if not creature then
            return
        end

        creature:addHealth(500)

        return true
    end, 4000, creature:getId())
end

GreedBerserkThink:register()

or
Lua:
local bossName = "Goshnar's Greed"
local floorId = 410
local replacementFloorId = 429
local floorCount = 4
local fromPos = {x = 4853, y = 4323, z = 15}
local toPos = {x = 4864, y = 4334, z = 15}
local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
condition:setParameter(CONDITION_PARAM_SUBID, 88888)
condition:setParameter(CONDITION_PARAM_TICKS, -1)
condition:setParameter(CONDITION_PARAM_BUFF_DAMAGEDEALT, 125)

local function replaceFloorsWithNewId(floors, oldId, newId)
    for _, pos in ipairs(floors) do
        local tile = Tile(pos)
        if tile then
            local item = tile:getItemById(oldId)
            if item then
                item:transform(newId)
            end
        end
    end
end

local function createRandomFloors()
    local randomFloors = {}
    for i = 1, floorCount do
        local randomX = math.random(fromPos.x, toPos.x)
        local randomY = math.random(fromPos.y, toPos.y)
        local randomZ = math.random(fromPos.z, toPos.z)
        table.insert(randomFloors, {x = randomX, y = randomY, z = randomZ})
        local newItem = Game.createItem(floorId, 1, {x = randomX, y = randomY, z = randomZ})
    end
    return randomFloors
end

local GreedTileStepIn = MoveEvent()

function GreedTileStepIn.onStepIn(creature, item, position, fromPosition, toPosition, isHotkey)
    if item:getId() == floorId then
        doTargetCombatHealth(0, creature, COMBAT_FIREDAMAGE, -5000, -5000, CONST_ME_HITBYFIRE)
    end
end

GreedTileStepIn:id(floorId)
GreedTileStepIn:register()

local GreedBerserkThink = CreatureEvent("GreedBerserk")

function GreedBerserkThink.onThink(creature)
    local hp = (creature:getHealth() / creature:getMaxHealth()) * 100
    if hp < 90 and not creature:getCondition(CONDITION_PARAM_BUFF_DAMAGEDEALT, CONDITIONID_DEFAULT, 88888) then
        local randomFloors = createRandomFloors()   
        addEvent(replaceFloorsWithNewId, 10 * 1000, randomFloors, floorId, replacementFloorId)
        creature:addCondition(condition)
    end

    addEvent(function(cid)
        local creature = Creature(cid)
        if not creature then
            return
        end

        creature:addHealth(500)

        return true
    end, 4000, creature:getId())
end

GreedBerserkThink:register()
 
Good evening! I am creating a boss with a mechanic where, when it reaches 90% HP, it gains a 25% damage buff (this already works using onThink). And an event is triggered where random tiles are generated within the room that deal 5K damage to the player stepping on them (this works using onStepIn, but I need to record the ID of the tile).

The issue is that when I register the tile ID, all other tiles with the same ID scattered across the map also deal 5K damage.

Lua:
local bossName = "Goshnar's Greed"
local floorId = 410
local replacementFloorId = 429
local floorCount = 4
local fromPos = {x = 4853, y = 4323, z = 15}
local toPos = {x = 4864, y = 4334, z = 15}
local condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
condition:setParameter(CONDITION_PARAM_SUBID, 88888)
condition:setParameter(CONDITION_PARAM_TICKS, -1)
condition:setParameter(CONDITION_PARAM_BUFF_DAMAGEDEALT, 125)

local function replaceFloorsWithNewId(floors)
    for _, pos in ipairs(floors) do
        local tile = Tile(pos)
        if tile then
            local item = tile:getItemById(floorId)
            if item then
                item:transform(replacementFloorId)
            end
        end
    end
end

local function createRandomFloors()
    local randomFloors = {}
    for i = 1, floorCount do
        local randomX = math.random(fromPos.x, toPos.x)
        local randomY = math.random(fromPos.y, toPos.y)
        local randomZ = math.random(fromPos.z, toPos.z)
        table.insert(randomFloors, {x = randomX, y = randomY, z = randomZ})
        local newItem = Game.createItem(floorId, 1, {x = randomX, y = randomY, z = randomZ})
    end
    return randomFloors
end

local function removeFloors(floors)
    for _, pos in ipairs(floors) do
        local tile = Tile(pos)
        if tile then
            local item = tile:getItemById(floorId)
            if item then
                item:remove()
            end
        end
    end
end

local GreedTile = MoveEvent()
function GreedTile.onStepIn(creature, item, position, fromPosition, toPosition, isHotkey)
    local itemId = item:getId()
    if itemId == floorId then
        doTargetCombatHealth(0, creature, COMBAT_FIREDAMAGE, -5000, -5000, CONST_ME_HITBYFIRE)
   end
end

local GreedBerserk = CreatureEvent("GreedBerserk")
function GreedBerserk.onThink(creature)
    local hp = (creature:getHealth() / creature:getMaxHealth()) * 100
    if hp < 90 and not creature:getCondition(CONDITION_PARAM_BUFF_DAMAGEDEALT, CONDITIONID_DEFAULT, 88888) then
        local randomFloors = createRandomFloors() 
        addEvent(replaceFloorsWithNewId, 10 * 1000, randomFloors)
        creature:addCondition(condition)
    end

    addEvent(function(cid)
        local creature = Creature(cid)
        if not creature then
            return
        end

        creature:addHealth(500)

        return true
    end, 4000, creature:getId())
end

GreedBerserk:register()
GreedTile:id(410)
GreedTile:register()
Didn't realise you were creating the floors in the script, you can still use the code I posted.

change your GreedTile code to:
Lua:
local GreedTile = MoveEvent()
function GreedTile.onStepIn(creature, item, position, fromPosition, toPosition, isHotkey)
    doTargetCombatHealth(0, creature, COMBAT_FIREDAMAGE, -5000, -5000, CONST_ME_HITBYFIRE)
end

GreedTile:aid(5000)
GreedTile:register()

And just setActionId when you create the item. Change to:
Lua:
local newItem = Game.createItem(floorId, 1, {x = randomX, y = randomY, z = randomZ})
if newItem then
    newItem:setActionId(5000)
end
 
Solution
Didn't realise you were creating the floors in the script, you can still use the code I posted.

change your GreedTile code to:
Lua:
local GreedTile = MoveEvent()
function GreedTile.onStepIn(creature, item, position, fromPosition, toPosition, isHotkey)
    doTargetCombatHealth(0, creature, COMBAT_FIREDAMAGE, -5000, -5000, CONST_ME_HITBYFIRE)
end

GreedTile:aid(5000)
GreedTile:register()

And just setActionId when you create the item. Change to:
Lua:
local newItem = Game.createItem(floorId, 1, {x = randomX, y = randomY, z = randomZ})
if newItem then
    newItem:setActionId(5000)
end

Thank you bro! Works perfectly!
 
Back
Top