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

Monster heal other after die

itzbrhue3

New Member
Joined
Feb 21, 2017
Messages
41
Solutions
1
Reaction score
1
Code:
function onKill(cid, target)
    if isCreature(cid) then
        if "N'Zoth Soul" == getCreatureName(target) then
            print(getCreatureName(target))
            print(target)
            doCreatureAddHealth("N'Zoth", 99999999)
        end
    end
    return true
end
im trying to make a monster that heals another monster after dies
using this code didn't work
tfs 0.4
 
Solution
I'm going to take the liberty of presuming N'Zoth Soul is some weaker companion monster and N'Zoth is a boss monster.

You will want to use onPrepareDeath(cid, deathList) for this. Register the script in creatureevents.xml. Presuming the filename is zothsouldie.lua, register it it like so:

XML:
<event type="onPrepareDeath" name="minionSacrifice" event="script" value="zothsouldie.lua"/>

Somewhere in your N'Zoth Soul monster file, register usage of that script.
XML:
<script>
    <event name="minionSacrifice"/>
</script>



Inside your script, inside the onPrepareDeath function, you'll want to check the area around the monster with something like this...
I'm going to take the liberty of presuming N'Zoth Soul is some weaker companion monster and N'Zoth is a boss monster.

You will want to use onPrepareDeath(cid, deathList) for this. Register the script in creatureevents.xml. Presuming the filename is zothsouldie.lua, register it it like so:

XML:
<event type="onPrepareDeath" name="minionSacrifice" event="script" value="zothsouldie.lua"/>

Somewhere in your N'Zoth Soul monster file, register usage of that script.
XML:
<script>
    <event name="minionSacrifice"/>
</script>



Inside your script, inside the onPrepareDeath function, you'll want to check the area around the monster with something like this:
local spectators = getSpectators(getCreaturePosition(cid), 9, 9)

This will give you a list of creatures around the dying monster. Then iterate over that list and check if one of the creatures is your boss N'Zoth Soul creature. There should be lots of examples of how iterate over lists in your existing server scripts, like this. The function you'll want to use to check is probably getCreatureName(tid) where tid is your second temp var in the ipairs iterator. (but we are checking for N'Zoth here, not your dying minion)

If found, save it's cid to a variable, just not named cid since that's already used. Maybe bcid. (boss creature id)
Then you can give it health via that bcid you saved: doCreatureAddHealth(bcid, 2^52)
(2^52 is short for "giant ass number just under mantissa max")

You can even do something like send a magic effect from the position of your dying minion monster to the position of your boss if you feel like getting fancy. For that you'd use doSendDistanceShoot(frompos, topos, type) using with frompos and topos being getCreaturePosition values from your dying minion and your boss respectively. You can see the list of shoot types in my handy chart here. Seems like SHOOT_EFFECT_HOLY and SHOOT_EFFECT_SMALLHOLY would be appropriate choices.


You should try to write this yourself, but if you get stuck report back.
Post automatically merged:

Untested, but it should work.
Lua:
local range = 9
local master = "N'Zoth"
local heal = 2^52
local shoot = true
local effect = SHOOT_EFFECT_SMALLHOLY -- if want bigger use SHOOT_EFFECT_HOLY
local yell = true
local judge = "MEDIOCRE!"

function onPrepareDeath(cid)
    local cpos = getCreaturePosition(cid)
    -- I live! I die! I live again!
    local witnessMe = getSpectators(cpos, range, range)
    local bcid = nil

    -- find master
    for i, tid in ipairs(witnessMe) do
        if getCreatureName(tid) == master then
            bcid = tid
            break
        end
    end

    if(bcid ~= nil) then
        local bpos = getCreaturePosition(bcid)
        doCreatureAddHealth(bcid, heal)
        if(shoot) then
            doSendDistanceShoot(cpos, bpos, effect)
        end
        if(yell) then
            doCreatureSay(bcid, judge, TALKTYPE_MONSTER_YELL)
        end
    end

    return true
end

If this helped you solve your problem, remember to hit the đź‘Ť in the post footer, and mark this post as your best answer.
 
Last edited:
Solution
Back
Top