Crystals
Member
- Joined
- Sep 28, 2024
- Messages
- 58
- Reaction score
- 10
TFS 1.4.2
Hi, maybe someone can help me with another script
I want to make a monster with "split damage"
Based on the principle:
* Boss + 3 mobs. If the boss receives e.g. 100 damage, it distributes 25% to all. With 2 mobs ~33%, with 1 mob - 50% between them.
But if it's one of the mobs that receives damage - it will receive 100% dmg.
Only hitting the boss distributes the damage between it and the mobs
I tried to make a script in different ways but I think I'm going in the wrong direction (or just .lua for the boss script is not enough)
Last thing I ended up with:
Hi, maybe someone can help me with another script

I want to make a monster with "split damage"
Based on the principle:
* Boss + 3 mobs. If the boss receives e.g. 100 damage, it distributes 25% to all. With 2 mobs ~33%, with 1 mob - 50% between them.
But if it's one of the mobs that receives damage - it will receive 100% dmg.
Only hitting the boss distributes the damage between it and the mobs
I tried to make a script in different ways but I think I'm going in the wrong direction (or just .lua for the boss script is not enough)
Last thing I ended up with:
LUA:
function onGetDamage(cid, attacker, damage, combatType)
if isMonster(cid) and getCreatureName(cid) == "Boss name" then
if getCreatureStorage(cid, 10000) == 1 then
return damage
end
doCreatureSetStorageValue(cid, 10000, 1)
local pos = getThingPos(cid)
local spectators = getSpectators(pos, 20, 20, false)
local monsters = {}
for i, creature in ipairs(spectators) do
if isMonster(creature) then
table.insert(monsters, creature)
end
end
local count = #monsters
if count > 0 then
local sharedDamage
if damage < 0 then
sharedDamage = math.ceil(damage / count)
else
sharedDamage = math.floor(damage / count)
end
for i, creature in ipairs(monsters) do
addEvent(function(target, dmg)
if isCreature(target) then
doCreatureAddHealth(target, dmg)
end
end, 1, creature, sharedDamage)
end
end
doCreatureSetStorageValue(cid, 10000, 0)
return 0
end
return damage
end