• 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]Creature heal at 40% life

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,809
Solutions
582
Reaction score
5,370
These Scripts will allow a creature to heal when under 40% until they are above 40%
Repp++ me if you want :)

Credit goes to Summ for fixing the spell Here

Make a new file named fortypercentheal.lua
Server\data\spells\scripts\custommonsterspells\
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
Edit Spells.lua
Server\data\spells\spells.lua
Add this
Lua:
<instant name="fortypercentheal" words="iauhdfjcadnvjn" lvl="999999" mana="50" aggressive="0" selftarget="1" exhaustion="1000" needlearn="0" event="script" value="custommonsterspells/fortypercentheal.lua">
	</instant>
Put this inside of the monster you want to heal at 40% and lower
Server\data\monster\
Lua:
<defense name="fortypercentheal" interval="2000" chance="100" min="30" max="50">
			<attribute key="areaEffect" value="blueshimmer"/>
		</defense>

Have fun everyone :D
 
Last edited:
I want to know it aswell.

Narko, he means monsters!

- - - Updated - - -

I had an idea!!

Monster Example:
Code:
[ . . . ]
<attacks>
<attack name="monsterSpell" interval="250" chance="5" range="2" min="11" max="33"/>
</attacks>
[ . . . ]

Then create the monster spell and check the life of the monster.
Code:
[ . . . ]
function onCastSpell(cid, var)
local percent = 40
  if 100 / (getCreatureMaxHealth(cid) / getCreatureHealth(cid)) <= percent then
      return TRUE
  end
[ . . . ]
 
Last edited:
you could try that, thats what my monster/creature has, it could be wrong but if it helps REP++

Lua:
<defenses armor="0" defense="0">
		<defense name="healing" interval="100" chance="700" min="35" max="40"/>
                <attribute key="areaEffect" value="blueshimmer"/>
	</defenses>
 
@narko Creature is a Monster. ;D

@G4BB3R I can't seem to find where to create the monster spell :p - where do I create it?

@Smokiee Jo That's the Current way. ;D ty though

For everyone - Imagine a Necromancer boss with 7000 life. Whenever it reaches 40% life (aka 2800 life) It will start healing - and if it get's under 1000 life it will run for it's life, until it's healed some hp again, but while at low health it would use harder spells and stuff xD.

Or a 'pk' monster. It would act more like a real player trying to kill you. Only heals when it get's in red life (knight).

Thank you everyone for helping so far ;D
 
@smokiee jo again - This does not exist currently. I am not looking for simple monster healing that heals every so often - I need/want a way to change how the monster's heal in general. I can make monsters 'regenerate health' by making a healing spell heal them 3% of their life with no animation. I can make the monsters heal every 15 seconds to full hp. I can make monsters heal with a chance of 15% every 2 seconds.

All above is possible with the current monster scripts however, I am hoping it's possible to create a new script that will make the monster only heal when it's hp goes in yellow, or red. (Aka heal when Monster hp is less then 40%)

thanks for the bump though ;D
 
"Shiverflare: G4BB3R I can't seem to find where to create the monster spell :p - where do I create it?"

Simple. Create a normal spell, then make it impossible to use with any vocation.
Code:
<instant name="necroTest" words="ramdom18093jsidjsidj12839" lvl="999999" mana="999999" aggressive="1" selftarget="0" script="necroTest.lua">
</instant>
Then use this name at:
Code:
<attacks>
<attack name="necroTest" interval="250" chance="5" range="2" min="11" max="33"/>
</attacks>
 
"Shiverflare: G4BB3R I can't seem to find where to create the monster spell :p - where do I create it?"

Simple. Create a normal spell, then make it impossible to use with any vocation.
Code:
<instant name="necroTest" words="ramdom18093jsidjsidj12839" lvl="999999" mana="999999" aggressive="1" selftarget="0" script="necroTest.lua">
</instant>
Then use this name at:
Code:
<attacks>
<attack name="necroTest" interval="250" chance="5" range="2" min="11" max="33"/>
</attacks>

I'll try this and reply soon :)
--edit--

When I did the spell in 'attacks' it did not work, but I changed it to defenses and it started working - almost.
the following code is the error in console. I believe I'm running 0.3.6 tfs (but I do not know how to check my tfs version)

Code:
[Error - Spell Interface]
data/spells/scripts/ms/fphm.lua:onCastSpell
Description:
data/spells/scripts/ms/fphm.lua:10: attempt to perform arithmetic on a boolean v
alue
stack traceback:
        data/spells/scripts/ms/fphm.lua:10: in function <data/spells/scripts/ms/
fphm.lua:8>

So everything is working except it can't do the math for the spell

the spell is this

Code:
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(uid)) <= percent then
      return TRUE
  end
end
this is line 10
Code:
  if 100 / (getCreatureMaxHealth(cid) / getCreatureHealth(uid)) <= percent then
any suggestions?

btw I will post Finished Scripts and stuff with tutorial on how to do it in first post after everything is done and working :)
 
Last edited:
The solution is to change uid to cid

if 100 / (getCreatureMaxHealth(cid) / getCreatureHealth(cid)) <= percent then
I have changed the line in question, and no longer get an error in console, but the monster still does not use the healing spell.
Can you possibly provide any other suggestion?

Thank you for all your help so far <3

-spells-
(note) changing agressive on/off does nothing
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. (note had to add an additional 'end' to complete spell)
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 last time created error)
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>
 
Last edited:
Sorry, I dont enter on otland for a few months XD
But the solution I think is instead of using:
Code:
return TRUE

Try using:
Code:
return doCombat(cid, combat, var)
 
These Scripts will allow a creature to heal when under 40% until they are above 40%
Repp++ me if you want :)

Credit goes to Summ for fixing the spell Here

Make a new file named fortypercentheal.lua
Server\data\spells\scripts\custommonsterspells\
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
Edit Spells.lua
Server\data\spells\spells.lua
Add this
Lua:
<instant name="fortypercentheal" words="iauhdfjcadnvjn" lvl="999999" mana="50" aggressive="0" selftarget="1" exhaustion="1000" needlearn="0" event="script" value="custommonsterspells/fortypercentheal.lua">
	</instant>
Put this inside of the monster you want to heal at 40% and lower
Server\data\monster\
Lua:
<defense name="fortypercentheal" interval="2000" chance="100" min="30" max="50">
			<attribute key="areaEffect" value="blueshimmer"/>
		</defense>

Have fun everyone :D
Funciono a la perfeccion (y)
 
Back
Top