Steve Albert
Banned User
- Joined
- Dec 9, 2018
- Messages
- 267
- Solutions
- 13
- Reaction score
- 104
This will spawn a creature at different percentages of health. Each index of the config table is a different percentage. count is the number of creatures to spawn. name is the name of the creature that will become the bossName's summon (but might also be effected by this script if the summon shares the same name as its master).
Save this as spawnSummons.lua in data/creaturescripts/scripts/
Add this to creaturescripts.xml in data/creaturescripts/
Add this to somewhere in compat.lua
Update or modify Creature: onTargetCombat in data/events/scripts/creature.lua
In events.xml in data/events/ make sure this code matches yours
Proof of Concept
Save this as spawnSummons.lua in data/creaturescripts/scripts/
Lua:
local config = {
[90] = {count = 2, name = "rabbit"},
[50] = {count = 3, name = "rabbit"},
[20] = {count = 5, name = "rabbit"},
}
x = {
Boss = {},
bossName = "rabbit",
}
local function percentage(n, p)
return math.ceil((n * p) / 100)
end
local function getHealthPercent(maxhealth, currenthealth)
for percent, tble in pairs(config) do
if percentage(maxhealth, percent) <= currenthealth and not x.Boss[percent] then
return tble, percent
end
end
return nil
end
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if creature and getBaseNameCompare(creature:getName():lower(), x.bossName) then
local health = creature:getHealth()
if health <= 20 then
x.Boss = {}
else
local t, index = getHealthPercent(creature:getMaxHealth(), health)
if t then
for i = 1, t.count do
doConvinceCreature(doSummonCreature(t.name, creature:getPosition()), creature:getId())
end
x.Boss[index] = 1
end
end
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
Add this to creaturescripts.xml in data/creaturescripts/
XML:
<event type="healthchange" name="spawnSummons" script="spawnSummons.lua" />
Add this to somewhere in compat.lua
Lua:
function getBaseName(name, length)
return name:sub(0, length)
end
function getBaseNameCompare(name, cmpr)
return getBaseName(name, #cmpr) == cmpr
end
Update or modify Creature: onTargetCombat in data/events/scripts/creature.lua
Lua:
function Creature:onTargetCombat(target)
if self and target:isMonster() then
if getBaseNameCompare(target:getName():lower(), 'rabbit') then
target:registerEvent("spawnSummons")
end
end
return RETURNVALUE_NOERROR
end
In events.xml in data/events/ make sure this code matches yours
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
Proof of Concept
Last edited: