• 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!

Lua onKill event Problem

charlyhustle

Member
Joined
Dec 9, 2011
Messages
46
Reaction score
6
Hi guys,

I wrote a script for my server (TFS 1.3) where if you kill a boss it will summon another boss.
When multiple players kill the monster theres a chance that the event will be triggered twice. I assume it's because of lasthit/mostdamage mechanic maybe? Here's my script:

Lua:
local timer = 1 * 5 * 1000

function onKill(player, target)
    local targetMonster = target:isMonster()
    local monsterType = target:getType()
    if not targetMonster then
        return true
    end
    
    local targetName = target:getName():lower()
    
    if targetName == 'lunarius' and monsterType:maxHealth() == 4400 then
        addEvent(Game.createMonster, timer, "Lunarius", Position(846, 1219, 11))
    end
    return true
end

I used monsterType:maxHealth() == 4400 because both bosses have the same name.
I read that my problem could be prevented when using onDeath instead of onKill but I have no idea how I can change my script.

Any help is greatly appreciated!

Thanks in advance!
 
Solution
Inside of your boss, put this, above loot.

Lua:
<script>
    <event name="onDeath_Lunarius" />
</script>

creaturescripts.xml
Lua:
<event type="death" name="onDeath_Lunarius" script="onDeath_Lunarius.lua" />

Note: login.lua does not need to be registered, since a player doesn't need to have this registered to them.

onDeath_Lunarius.lua
Lua:
local timer = 1 * 5 * 1000

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)

	-- I'm assuming that Lunarius is a multi-stage boss and requires this check for some reason...
	-- But if that is not the case.. you can literally get rid of this if statement.
	if creature:getMaxHealth() == 4400 then
		addEvent(Game.createMonster, timer...

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,810
Solutions
433
Reaction score
3,949
Inside of your boss, put this, above loot.

Lua:
<script>
    <event name="onDeath_Lunarius" />
</script>

creaturescripts.xml
Lua:
<event type="death" name="onDeath_Lunarius" script="onDeath_Lunarius.lua" />

Note: login.lua does not need to be registered, since a player doesn't need to have this registered to them.

onDeath_Lunarius.lua
Lua:
local timer = 1 * 5 * 1000

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)

	-- I'm assuming that Lunarius is a multi-stage boss and requires this check for some reason...
	-- But if that is not the case.. you can literally get rid of this if statement.
	if creature:getMaxHealth() == 4400 then
		addEvent(Game.createMonster, timer, "Lunarius", Position(846, 1219, 11))
	end
	return true
end
 
Last edited:
Solution
OP
OP
charlyhustle

charlyhustle

Member
Joined
Dec 9, 2011
Messages
46
Reaction score
6
Inside of your boss, put this, above loot.

Lua:
<script>
    <event name="onDeath_Lunarius" />
</script>

creaturescripts.xml
Lua:
<event type="death" name="onDeath_Lunarius" script="onDeath_Lunarius.lua" />

Note: login.lua does not need to be registered, since a player doesn't need to have this registered to them.

onDeath_Lunarius.lua
Lua:
local timer = 1 * 5 * 1000

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)

    -- I'm assuming that Lunarius is a multi-stage boss and requires this check for some reason...
    -- But if that is not the case.. you can literally get rid of this if statement.
    if creature:maxHealth() == 4400 then
        addEvent(Game.createMonster, timer, "Lunarius", Position(846, 1219, 11))
    end
    return true
end

Thank you so much! Will test it later if I find the time but looks very promising.

And yes it's kind of a multistage boss (Human form/ werewolf form)

I will report back here, after I tested it!
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,810
Solutions
433
Reaction score
3,949
Thank you so much! Will test it later if I find the time but looks very promising.

And yes it's kind of a multistage boss (Human form/ werewolf form)

I will report back here, after I tested it!
Sweet. Let me know how it goes.
 
Top