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

Solved Monster Heal at 40% not before - no error in console

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,829
Solutions
586
Reaction score
5,410
As thread title - Creating a monster that does not heal until it reaches 40% or lower.

If there is another way to achieve this please let me know. ^_^

I have took an intense healing spell, and modified it with some help, to hopefully check if the monster has below 40% hp and if so cast the spell and give a blue shimmer if it's been activated.
The monster is a slightly modified monk.
No vocation can use the spell, although I would assume gods should still be able to cast the spell. Also when reloading monsters/spells there is no error's for either the spell or monster.

-spells-
(note) changing agressive on/off does nothing (ms=monster script | fphm=fourty percent healing monster) :rolleyes:
XML:
		<instant name="fphm" words="iauhdfjcadnvjn" lvl="999999" mana="50" aggressive="0" selftarget="1" exhaustion="1000" needlearn="0" event="script" value="ms/fphm.lua">
	</instant>
Actual Spell being used. (when casted with the word "iauhdfjcadnvjn" by a god nothing happens, no error's in console either)
XML:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
setHealingFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 5, 5, 5, 6)

function onCastSpell(cid, var)
local percent = 40
	if 100 / (getCreatureMaxHealth(cid) / getCreatureHealth(cid)) <= percent then
      return TRUE
  end
end
-Monster-
If spell in attack does nothing/ if in defense does nothing. (however when in defense it would spam the error for not finding a required boolean (the moment it was summoned), before I changed part of the spell from getCreatureHealth(uid) - to - getCreatureHealth(cid))
XML:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Fphm" nameDescription="a fphm" race="blood" experience="200" speed="220" manacost="1200">
	<health now="240" max="240"/>
	<look type="57" corpse="6080"/>
	<targetchange interval="5000" chance="8"/>
	<strategy attack="100" defense="0"/>
	<flags>
		<flag summonable="1"/>
		<flag attackable="1"/>
		<flag hostile="1"/>
		<flag illusionable="1"/>
		<flag convinceable="0"/>
		<flag pushable="0"/>
		<flag canpushitems="1"/>
		<flag canpushcreatures="1"/>
		<flag targetdistance="1"/>
		<flag staticattack="90"/>
		<flag runonhealth="0"/>
	</flags>
	<attacks>
		<attack name="melee" interval="2000" skill="30" attack="70"/>
	</attacks>
	<defenses armor="20" defense="22">
		<defense name="fphm" interval="1000" chance="100" min="30" max="50">
			<attribute key="areaEffect" value="blueshimmer"/>
		</defense>
		<defense name="speed" interval="1000" chance="10" speedchange="300" duration="3000">
			<attribute key="areaEffect" value="redshimmer"/>
		</defense>
	</defenses>
	<elements>
		<element holyPercent="50"/>
		<element deathPercent="50"/>
		<element physicalPercent="-15"/>
	</elements>
	<voices interval="5000" chance="10">
		<voice sentence="Repent Heretic!"/>
		<voice sentence="A prayer to the almighty one!"/>
		<voice sentence="I will punish the sinners!"/>
	</voices>
	<loot>
		<item id="8300" chance="25"/><!-- embounding crystal -->
		<item id="8305" chance="25"/><!-- refining material -->
		<item id="2148" countmax="20" chance="24000"/><!-- gold coin -->
		<item id="2689" chance="20000"/><!-- bread -->
		<item id="1949" chance="18000"/><!-- scroll -->
		<item id="2044" chance="12000"/><!-- lamp -->
		<item id="2015" chance="6666"/><!-- brown flask -->
		<item id="2642" chance="6666"/><!-- sandals -->
		<item id="2467" chance="4000"/><!-- leather armor -->
		<item id="2401" chance="20000"/><!-- staff -->
		<item id="1987" chance="100000"><!-- bag -->
			<inside>
					<item id="2177" chance="3000"/><!-- life crystal -->
					<item id="2193" chance="1500"/><!-- ankh -->
					<item id="2166" chance="700"/><!-- power ring -->
			</inside>
		</item>
	</loot>
</monster>
I have a feeling that the problem lies with the spell itself, it's like the spell is actually casting but it has no function to start the cast.
Just a hunch but I can't figure out what's wrong.:huh:
 
Last edited:
Try this spell:
Lua:
function onCastSpell(cid, var)
    if (getCreatureHealth(cid) / getCreatureMaxHealth(cid)) <= 0.4 then
        doCreatureAddHealth(cid, math.random(HEAL_MIN, HEAL_MAX))
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        return true
  end
end
 
Try this spell:
Lua:
function onCastSpell(cid, var)
    if (getCreatureHealth(cid) / getCreatureMaxHealth(cid)) <= 0.4 then
        doCreatureAddHealth(cid, math.random(HEAL_MIN, HEAL_MAX))
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        return true
  end
end
I get this error using Just your code
Lua:
[Error - Spell Interface]
data/spells/scripts/ms/fphm.lua:onCastSpell
Description:
data/spells/scripts/ms/fphm.lua:3: bad argument #1 to 'random' (number expected,
 got nil)
stack traceback:
        [C]: in function 'random'
        data/spells/scripts/ms/fphm.lua:3: in function <data/spells/scripts/ms/f
phm.lua:1>


I get this error using your code + spell
Lua:
[Error - Spell Interface]
data/spells/scripts/ms/fphm.lua:onCastSpell
Description:
data/spells/scripts/ms/fphm.lua:10: bad argument #1 to 'random' (number expected
, got nil)
stack traceback:
        [C]: in function 'random'
        data/spells/scripts/ms/fphm.lua:10: in function <data/spells/scripts/ms/
fphm.lua:8>
the spell
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
setHealingFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 5, 5, 5, 6)

function onCastSpell(cid, var)
    if (getCreatureHealth(cid) / getCreatureMaxHealth(cid)) <= 0.4 then
        doCreatureAddHealth(cid, math.random(HEAL_MIN, HEAL_MAX))
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        return true
  end
end

Thank for the help so far
The Error's only occur when the monster get's below 40% hp
 
You are supposed to change HEAL_MIN and HEAL_MAX for real number values. Example: math.random(40, 200)

Also you do not need this part:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
setHealingFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 5, 5, 5, 6)
 
It works! :D

I was 'hoping' to use the same thing in different monsters.

Is it possible to have the math.random load from the monster file?

Lua:
<defense name="fphm" interval="1000" chance="100" min="30" max="50">

If not it's alright as-is, since it works :cool:
 
Lua:
local monsters = {
	["Demon"] = {400, 500, 0.4},    -- minimum, maximum, percent
	["Behemoth"] = {30, 400, 0.3}
}

function onCastSpell(cid, var)
	if not(monsters[getCreatureName(cid)]) then
		print("No healing values for monster: " .. getCreatureName(cid))
		return true
	end
	
	local min, max, percent = monsters[getCreatureName(cid)][1], monsters[getCreatureName(cid)][2], monsters[getCreatureName(cid)][3]
        if (getCreatureHealth(cid) / getCreatureMaxHealth(cid)) <= percent then
            doCreatureAddHealth(cid, math.random(min, max))
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
            return true
        end
end
 
Lua:
local monsters = {
	["Demon"] = {400, 500, 0.4},    -- minimum, maximum, percent
	["Behemoth"] = {30, 400, 0.3}
}

function onCastSpell(cid, var)
	if not(monsters[getCreatureName(cid)]) then
		print("No healing values for monster: " .. getCreatureName(cid))
		return true
	end
	
	local min, max, percent = monsters[getCreatureName(cid)][1], monsters[getCreatureName(cid)][2], monsters[getCreatureName(cid)][3]
        if (getCreatureHealth(cid) / getCreatureMaxHealth(cid)) <= percent then
            doCreatureAddHealth(cid, math.random(min, max))
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
            return true
        end
end

It works perfectly You are amazing! xD
Now I just need to fiddle with it until I can make monsters cast spells when they are low hp >:D
 
Back
Top