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

TFS 1.X+ Trying to make monsters have death animations, TFS 1.4.2

BigDoink

New Member
Joined
Apr 15, 2023
Messages
7
Reaction score
0
I'm trying to get monsters have a death animation, My idea is that when they die they'll all use the same death animation then once the animation is complete it spawns a lootable corpse that follows the targeted creatures .xml loot table after the animation is complete.

I had tried this script, But couldn't work it out.
Lua:
function onDeath(creature, corpse)
        doSendMagicEffect (106)
    return true
end
 
Solution
I was thinking about how this would be written and I'm kind of stumped on this part, After the player kills the monster and the script teleports the corpse to lets say 0, 0, 7 and than someone else kills a monster wouldn't their corpse get teleported over the top of the first corpse and it be possible the corpses get mixed up? In my server all corpses are just gonna be a bag all with the same ID and with an animation before to make it simple.
Yep. That's why you need to tag the corpse with a custom attribute, so that each corpse is unique and you'll always be able to find it.

So.

Teleport corpse
Tag corpse
AddEvent
Loop through items on tile until you find the the tag
Teleport corpse back
Post automatically merged:

Over discord we...
I'd start with a onDeath revscript


You can use luascript.cpp to find 95% of your normal functions


effect 106 is CONST_ME_THECUBE
I always prefer to use the name instead of the number, just so it's easier to read the code in the future.

You'll also want to register the script into the monsters.


Enable onSpawn by changing this to a 1 instead of 0

put your script into data/scripts

Lua:
local creatureevent = CreatureEvent("MonsterDeathAnimation")

function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    local position = creature:getPosition()
    position:sendMagicEffect(CONST_ME_THECUBE)
    return true
end

creatureevent:register()



local eventcallback = EventCallback

eventcallback.onSpawn = function(self, position, startup, artificial)
    self:registerEvent("MonsterDeathAnimation")
    return true
end

eventcallback:register()
 
I'd start with a onDeath revscript


You can use luascript.cpp to find 95% of your normal functions


effect 106 is CONST_ME_THECUBE
I always prefer to use the name instead of the number, just so it's easier to read the code in the future.

You'll also want to register the script into the monsters.


Enable onSpawn by changing this to a 1 instead of 0

put your script into data/scripts

Lua:
local creatureevent = CreatureEvent("MonsterDeathAnimation")

function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    local position = creature:getPosition()
    position:sendMagicEffect(CONST_ME_THECUBE)
    return true
end

creatureevent:register()



local eventcallback = EventCallback

eventcallback.onSpawn = function(self, position, startup, artificial)
    self:registerEvent("MonsterDeathAnimation")
    return true
end

eventcallback:register()
What do you mean register into the monsters? My monsters are created using xml
Post automatically merged:

Are you talking about the monster.lua?
 
What do you mean register into the monsters? My monsters are created using xml
Post automatically merged:

Are you talking about the monster.lua?
By default, monsters have no scripts registered to them.

In order for onDeath to trigger, you must register the script to the monster.

Your 2 choices are..
- Register it in every single monster file manually..
XML:
<script>
    <event name="MonsterDeathAnimation" />
</script>
- Or Register the script to the creatures when they spawn (the way I showed above.)
 
By default, monsters have no scripts registered to them.

In order for onDeath to trigger, you must register the script to the monster.

Your 2 choices are..
- Register it in every single monster file manually..
XML:
<script>
    <event name="MonsterDeathAnimation" />
</script>
- Or Register the script to the creatures when they spawn (the way I showed above.)
Would switching to lua monster types be good or is it still to early for that? and if I did switch to lua monsters would registering it be the same?
Post automatically merged:

I got it to work, But the corpse id spawns in as soon as the creature dies instead of after the animation completes
 
Last edited:
Yeah towards that end..

I would try teleporting the corpse to a far-off tile, where no player can access.
Then set an addEvent to teleport the corpse back to the tile.
You'd have to play around with the timing, to make it come back when the animation finishes..
But that should work.

Might have to add a custom 'tag' to the corpse, so you can find it to teleport it back.. but should be easy enough to set a custom attribute.
 
Yeah towards that end..

I would try teleporting the corpse to a far-off tile, where no player can access.
Then set an addEvent to teleport the corpse back to the tile.
You'd have to play around with the timing, to make it come back when the animation finishes..
But that should work.

Might have to add a custom 'tag' to the corpse, so you can find it to teleport it back.. but should be easy enough to set a custom attribute.
I was thinking about how this would be written and I'm kind of stumped on this part, After the player kills the monster and the script teleports the corpse to lets say 0, 0, 7 and than someone else kills a monster wouldn't their corpse get teleported over the top of the first corpse and it be possible the corpses get mixed up? In my server all corpses are just gonna be a bag all with the same ID and with an animation before to make it simple.
 
I was thinking about how this would be written and I'm kind of stumped on this part, After the player kills the monster and the script teleports the corpse to lets say 0, 0, 7 and than someone else kills a monster wouldn't their corpse get teleported over the top of the first corpse and it be possible the corpses get mixed up? In my server all corpses are just gonna be a bag all with the same ID and with an animation before to make it simple.
Yep. That's why you need to tag the corpse with a custom attribute, so that each corpse is unique and you'll always be able to find it.

So.

Teleport corpse
Tag corpse
AddEvent
Loop through items on tile until you find the the tag
Teleport corpse back
Post automatically merged:

Over discord we made the code.

Lua:
local config = {
    corpseTempPosition = Position(999, 1004, 5),
    delay = 1000,
    key = "corpseIdentifier"
}

local corpseidentifier = 0

local function moveCorpse(position, corpseIdentifier)
    local tileItems = Tile(config.corpseTempPosition):getItems()
    for _, corpse in pairs(tileItems) do
        local identifier = corpse:getCustomAttribute(config.key)
        if identifier == corpseIdentifier then
            corpse:moveTo(position)
            corpse:removeAttribute(config.key)
            return
        end
    end
    if corpseidentifier == corpseIdentifier then
        corpseidentifier = 0
    end
end

local creatureevent = CreatureEvent ("MonsterDeathAnimation")

function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if corpse and corpse:isItem() then
        local position = creature:getPosition()
        position:sendMagicEffect(106)
    
        corpseidentifier = corpseidentifier + 1
        corpse:moveTo(config.corpseTempPosition)
        corpse:setCustomAttribute(config.key, corpseidentifier)
        addEvent(moveCorpse, config.delay, position, corpseidentifier)
    end
    return true
end

creatureevent:register()

local eventcallback = EventCallback

eventcallback.onSpawn = function(self, position, startup, artificial)
    self:registerEvent("MonsterDeathAnimation")
    return true
end

eventcallback:register()
 
Last edited:
Solution
Back
Top