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

Spell Make Monsters Use Health Potions

Shadowsong

Game Developer & Graphic Designer
Joined
Feb 23, 2010
Messages
3,446
Solutions
21
Reaction score
3,001
Location
Bosnia & Herzegovina
YouTube
ShivaShadowsong
Hello, here is a simple & handy script I wrote for Necronia that I feel like sharing.

For:
TFS 0.3.6

What does it do?
It lets you virtually add HP potions to a monster, and you can make the monster use them when it is on low HP. Once they run out of HP potions, they can no longer use them.
You can configure how much they will heal, how many potions they will carry, which monsters use it, etc.

Watch as he heals when I get him below a certain threshold of HP:

WQKZawQ.gif


Implementation:
Make a file called potions.lua in your spells/scripts/monsters/ folder.
Paste this script into it:

Code:
function onCastSpell(cid, var)
    -- Monsters with potions
    -- Author: Shiva Shadowsong
    -- CONFIGURATION--
    local MON_HPOT = 24582 -- MON_HPOT = Storage used to check how many potions the creature used so far --
    -- Configure how much health each potion will heal:
    local smallPot, medPot, bigPot, greatPot = math.random(20,80), math.random(80,200), math.random(170,400),math.random(280,550)

    --[[ In this following table, you can configure which creatures will use the potions, and
    the other parameters related to their usage.
    pots = How many potions will this creature have?
    potType = put smallPot, medPot, bigPot or greatPot here | amounts these potions heal are defined above
    threshold = Creature will use the potions only when his HP reaches (threshold*100)% or below. (e.g. threshold = 0.3 means they will heal on 30% or less health)
    ]]--
    local creaturesForPots = {
    ["Beduin"] = {pots = 3, potType = medPot, threshold = 0.3 , text = "*gulp*" },
    ["Beduin Scimitarist"] = {pots = 4, potType = smallPot, threshold = 0.4, text = "*gulp*" },
    ["Beduin Caravanleader"] = {pots = 5, potType = greatPot, threshold = 0.3, text = "*gulp*" },
    }
    ------------------------------------------------------
        local mon = getCreatureName(cid)
        if creaturesForPots[mon] ~= nil then
            -- Usage of potion:
            if getCreatureHealth(cid) <= (getCreatureMaxHealth(cid)*creaturesForPots[mon].threshold) then
                if getPlayerStorageValue(cid, MON_HPOT) < creaturesForPots[mon].pots-1 then
                doCreatureSay(cid, creaturesForPots[mon].text, TALKTYPE_MONSTER)
                doCreatureAddHealth(cid, creaturesForPots[mon].potType)
                doSendMagicEffect(getCreaturePosition(cid), 12)
                setPlayerStorageValue(cid, MON_HPOT, getPlayerStorageValue(cid, MON_HPOT)+1)
                end
            end 
        else
        print("Some monster is trying to use the Health Potion spell script, but is not defined in the creatures table in healthPotion.lua")
        return false
        end
    return true
end

Now, in your spells.xml file, add this:

Code:
  <instant name="Monster Potion" words="monsterpot" lvl="1" mana="1" prem="0" selftarget="1" aggressive="0" exhaustion="2000" needlearn="0" event="script" value="monsters/potions.lua">
    <vocation id="0"/>
    </instant>

And finally, when you want to make a monster use this spell, add it to his XML file.
So for example, I'll go into the file of Beduin Caravanleader and add this line into his attacks:

<attacks>
<attack name="melee" interval="2200" min="-22" max="-88"/>
<attack name="Monster Potion" interval="3000" chance="100"/>
</attacks>
 
Last edited:
I see why I wasnt able to kill that Nomad Leader! haha, Amazing script Shiva, as always impressive.

Greetings, Liro.
 
Back
Top