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

When a monster kills another monster

zezin009

Member
Joined
May 30, 2019
Messages
49
Reaction score
24
Hello, I'm wonderying whats happend when a monster kills another monster...?
When I use the onKill function, it doesn't work in this case!
I already tried to use onDeath function, but I think i'm missing something to understand what it need to work.

I have TSF 0.3, and my code is something like this:

Lua:
function onKill(cid, target, lastHit)

if getCreatureName(target) == "Rat" then
doCombatAreaHealth(cid, COMBAT_FIREDAMAGE, getThingPosition(target), 3, -30, -50  , 5)
return true
end

Notice that I want to make the Rat to explode after killing him!
The problem is, when the Rat is killed by another monster, this code don't run.
If the killer is a player, or his summon, it works.

Any ideas?
 
Solution
Thanks!
Post automatically merged:

I found the way to do it, and i'm thanks to Exedion for the awnser in this topic: Lua - Register Creature Events In Monsters (https://otland.net/threads/register-creature-events-in-monsters.114969/)

I just added in my Rat.xml the follow script:
Lua:
<script>
        <event name="Death Rat"/>
</script>

Which is the name of my file in creaturescripts.xml:
Lua:
<event type="death" name="Death Rat" event="script" value="death_rat_script.lua"/>

Also, just for registration, my death_rat_script.lua is:
Lua:
function onDeath(cid, corpse, deathList)

if getCreatureName(cid) == "Rat" then
doCombatAreaHealth(cid, COMBAT_FIREDAMAGE, getThingPosition(cid), 3, -30, -50, 5)
end

return true
end

Now, when the...
onKill is called for players only, you want to use onDeath and register the script on rat.xml file.

So your onDeath should only have the
sendMagicEffect and creature/monster on position. Im unsure of how functions look in 0.3 but that is what you need to do.
 
onKill is called for players only, you want to use onDeath and register the script on rat.xml file.

So your onDeath should only have the
sendMagicEffect and creature/monster on position. Im unsure of how functions look in 0.3 but that is what you need to do.

Thanks!
Post automatically merged:

I found the way to do it, and i'm thanks to Exedion for the awnser in this topic: Lua - Register Creature Events In Monsters (https://otland.net/threads/register-creature-events-in-monsters.114969/)

I just added in my Rat.xml the follow script:
Lua:
<script>
        <event name="Death Rat"/>
</script>

Which is the name of my file in creaturescripts.xml:
Lua:
<event type="death" name="Death Rat" event="script" value="death_rat_script.lua"/>

Also, just for registration, my death_rat_script.lua is:
Lua:
function onDeath(cid, corpse, deathList)

if getCreatureName(cid) == "Rat" then
doCombatAreaHealth(cid, COMBAT_FIREDAMAGE, getThingPosition(cid), 3, -30, -50, 5)
end

return true
end

Now, when the monsters kill each other, the script runs!

Thanks again, Mjmackan
 
Last edited:
Thanks!
Post automatically merged:

I found the way to do it, and i'm thanks to Exedion for the awnser in this topic: Lua - Register Creature Events In Monsters (https://otland.net/threads/register-creature-events-in-monsters.114969/)

I just added in my Rat.xml the follow script:
Lua:
<script>
        <event name="Death Rat"/>
</script>

Which is the name of my file in creaturescripts.xml:
Lua:
<event type="death" name="Death Rat" event="script" value="death_rat_script.lua"/>

Also, just for registration, my death_rat_script.lua is:
Lua:
function onDeath(cid, corpse, deathList)

if getCreatureName(cid) == "Rat" then
doCombatAreaHealth(cid, COMBAT_FIREDAMAGE, getThingPosition(cid), 3, -30, -50, 5)
end

return true
end

Now, when the monsters kill each other, the script runs!

Thanks again, Mjmackan
If my answer helped you, please mark it as solution.
Btw you can remove if getCreatureName part aswell, its unnecessary.

Lua:
function onDeath(cid, corpse, deathList)
doCombatAreaHealth(cid, COMBAT_FIREDAMAGE, getThingPosition(cid), 3, -30, -50, 5)
return true
end

I don't think it throws any errors for you but you could also use doSendMagicEffect instead since it already register the monsters death onDeath.
 
Solution
If my answer helped you, please mark it as solution.
Btw you can remove if getCreatureName part aswell, its unnecessary.

Lua:
function onDeath(cid, corpse, deathList)
doCombatAreaHealth(cid, COMBAT_FIREDAMAGE, getThingPosition(cid), 3, -30, -50, 5)
return true
end

I don't think it throws any errors for you but you could also use doSendMagicEffect instead since it already register the monsters death onDeath.

Done

It's working just like you said, thanks!
 
Back
Top