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.
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()