Author: Cybermaster
Storage: 9008
Description
This spell protects the player from fatal hits. When a player is attacked and the attack is equal or higher than player's health, the safeguard reduces the value of attack to -1 to avoid player from dying instantly.
Setup
creaturescripts/creaturescripts.xml
Lua:
<event type="statschange" name="safeguard" event="script" value="safeguard.lua"/>
register @ Login.lua:
Lua:
registerCreatureEvent(cid,'safeguard')
creaturescripts/scripts/safeguard.lua
Lua:
local storage = 9008
function onStatsChange(cid, attacker, type, combat, value)
if isPlayer(cid) and getCreatureStorage(cid,storage) > 0 and type == STATSCHANGE_HEALTHLOSS then
if value >= getCreatureHealth(cid) and getCreatureHealth(cid) > 1 then
value = getCreatureHealth(cid)-1
doCreatureSetStorage(cid, storage, 0)
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)
doPlayerSendCancel(cid,'You are no longer protected against fatal hits!')
doTargetCombatHealth(attacker, cid, combat, -value, -value, CONST_ME_MAGIC_GREEN)
return false
end
end
return true
end
spells/spells.xml
Lua:
<instant name="Safeguard" words="utamo mort" lvl="60" mana="100" prem="1" exhaustion="3000" needlearn="0" enabled="1" event="script" value="safeguard.lua">
<vocation id="2"/>
<vocation id="4"/>
<vocation id="6"/>
<vocation id="8"/>
</instant>
spells/scripts/safeguard.lua
Lua:
local storage = 9008
function onCastSpell(cid, var)
if getCreatureStorage(cid, storage) == 1 then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
doPlayerSendCancel(cid,'You are already protected against fatal hits.')
return false
end
doCreatureSetStorage(cid, storage, 1)
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)
doPlayerSendCancel(cid,'You are protected against fatal hits.')
return true
end
:thumbup: Hope it works for you
Last edited: