• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved How to make monster spell only heal monsters

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,454
Solutions
1
Reaction score
627
Location
Estonia
Trying to make a monster who is using mass heal, but is not healing PLAYERS

Try1:
Made a custom defensive spell for monster:
What it does:
It checks if the target is player, if it is: Then he doesn't heal him
Problems:
This spell doesn't heal caster himself and any other monsters, even when they are at the same area
xml
Code:
    <defenses armor="15" defense="15">
        <defence name="monsterHeal" interval="2000" min="5" max="5"/>
    </defenses>
spells.xml
Code:
    <instant        name="monsterHeal"                  words="###52"   aggressive="1"      blockwalls="0"          needtarget="1"          needlearn="1"    
                    script="custom monsters/bandit druid - heal.lua"/>
script for the spell
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
local area = createCombatArea(area9x9)
setCombatArea(combat, area)

function onTargetCreature(creature, target)
  if isPlayer(target) then
  return true
  end

  local min, max = 10, 10
  doTargetCombatHealth(0, target, COMBAT_HEALING, min, max, CONST_ME_NONE)
  return true
end
setCombatCallback(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(cid, var)
   return doCombat(cid, combat, var)
end

Try2:
Made a custom attack spell for monster:
What it does:
It doesn't heal the player because the area effect removed the healing are from the position he is in.
Problems:
This spell doesn't heal caster himself and any other monsters, even when they are at the same area
xml
Code:
 <attack name="monsterHeal" interval="2000" min="5" max="5"/>
spells.xml
Code:
    <instant        name="monsterHeal"                  words="###52"   aggressive="1"      blockwalls="0"          needtarget="1"          needlearn="1"    
                    script="custom monsters/bandit druid - heal.lua"/>
script for the spell
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
local area = createCombatArea(area9x9) --this time this area excludes the impact point
setCombatArea(combat, area)

function onCastSpell(cid, var)
   return doCombat(cid, combat, var)
end

Try3&4:
Used healing attribute for attack & defence:
What it does:
It heals everybody who are in the range.
Problems:
It also heals the player (what i don't want to heal)
xml
Code:
<attack name="healing" interval="2000" min="100" max="100" min="5" max="5" range="8" radius="10" target="1"/>

Try5:
added radius for custom spells.
Radius didn't change anything
<attack name="monsterHeal" interval="2000" min="5" max="5" radius="10"/>


Here are all my futile attempts, Anyone has any idea how to fix any of these solutions or another way around idea?

extra:
Found this in sourcecode:
Code:
        if ((attr = node.attribute("radius"))) {
            int32_t radius = pugi::cast<int32_t>(attr.value());

            //target spell
            if ((attr = node.attribute("target"))) {
                needTarget = attr.as_bool();
            }

            AreaCombat* area = new AreaCombat();
            area->setupArea(radius);
            combat->setArea(area);
        }
Is there any way i could set custom combatArea for the radius? without changing sourcecode
 
Last edited:
These functions / methods would help
Code:
Game.getSpectators
player:getParty():getMembers()
https://github.com/otland/forgottenserver/wiki/Metatable:Party
https://github.com/otland/forgottenserver/wiki/Metatable:Player
https://github.com/otland/forgottenserver/wiki/Metatable:Creature
 
You can use onTargetCreature
Code:
function onTargetCreature(creature, target)
    if target:isPlayer() then
        return true
    end

    local min, max = 100, 200
    doTargetCombatHealth(0, target, COMBAT_HEALING, min, max, CONST_ME_NONE)
    return true
end

combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
 
These functions / methods would help
Code:
Game.getSpectators
player:getParty():getMembers()
https://github.com/otland/forgottenserver/wiki/Metatable:Party
https://github.com/otland/forgottenserver/wiki/Metatable:Player
https://github.com/otland/forgottenserver/wiki/Metatable:Creature
nice links, but i don't know what im looking for from these..

You can use onTargetCreature

Code:
function onTargetCreature(creature, target)
    if target:isPlayer() then
        return true
    end

    local min, max = 100, 200
    doTargetCombatHealth(0, target, COMBAT_HEALING, min, max, CONST_ME_NONE)
    return true
end

combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")


this line gives me errors:
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
attempt to index local 'combat' (a number value)

if i take the "combat:" away i get (a nil value)
 
Sorry, should be setCombatCallBack(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature") since you're not using Combat metatable.
 
Sorry, should be setCombatCallBack(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature") since you're not using Combat metatable.
sry i wasn't clear enough.

with that: "if i take the "combat:" away i get (a nil value)" sentence said i ment i used this: setCombatCallBack(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
and yeah, it says its a nil value

did i i set up the function correctly?
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)

local area = createCombatArea(area9x9)
setCombatArea(combat, area)

function onTargetCreature(creature, target)
    if target:isPlayer() then
        return true
    end

    local min, max = 11, 11
    doTargetCombatHealth(0, target, COMBAT_HEALING, min, max, CONST_ME_NONE)
    return true
end

setCombatCallBack(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(cid, var)

    return doCombat(cid, combat, var)
end

i tried it inside the onCastSpell function too, but same thing. a nil value in this line:
setCombatCallBack(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
 
Or maybe its nil because in monster.xml i am using defence instead of attack?
Code:
    <defenses armor="15" defense="15">
        <defense name="monsterHeal" interval="2000" min="100" max="100" />
    </defenses>

also here i my spells.xml just incase

Code:
    <instant        name="monsterHeal"                  words="###52"   aggressive="0"      blockwalls="0"          needtarget="1"          needlearn="1"      
                    script="custom monsters/bandit druid - heal.lua"/>
 
currently i worked around the issue by changing the spell area and making monster heal everything around me with large scale.
But for future, i most likely would like to make the "ignore" thing possible.
 
didn't notice before.. When i use Healing spell as attack its not healing anyone..

i tried to set combatCallback, but it still gives no hp.

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)

local area = createCombatArea(area9x9)
setCombatArea(combat, area)

function onGetFormulaValues(cid, level, maglevel)
    min = 100
    max = 100
    return min, max
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var, isHotkey)
    return doCombat(cid, combat, var)
end

also i get no errors
 
Alright new day new attempts to fix the spell.

I found out that: if i take away the area where it should not heal (the area where player is) i find that he DOES heal the target...
so the healing works, but ONLY on the target..
I assume on above code the: setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
Is not expanding with area.

Well now, how can i make sure the heal radius also widens with combatCallback? If that's even possible.
 
O boy.. i just realized , the creature never healed himself nor other monsters. Only the player if i got close enough, how can i make monster mass heal , heal everybody? that's the question.
 
updated post1. Made a recap of all my tests

EDIT:
I give it 1-2 days and if this issue is not still solved i will have to remake entire healing system.

I hope we still find a solution
 
Last edited:
Back
Top