tuduras
Well-Known Member
- Joined
- Jun 4, 2017
- Messages
- 340
- Solutions
- 2
- Reaction score
- 58
when set full attack more dmg , when full defense less damage
Hello I added code to data/events/script/creature
and works only more healing when put full defense.
Can someone knows how to do it to work?
Maybe add somethink in data/scripts?
Best regards!
Hello I added code to data/events/script/creature
LUA:
function Creature:onHealthChange(attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if attacker and attacker:isPlayer() then
local mode = attacker:getFightMode()
local multiplier = 1.0
if mode == FIGHTMODE_ATTACK then
multiplier = 1.5
elseif mode == FIGHTMODE_DEFENSE then
multiplier = 0.5
end
if multiplier ~= 1.0 then
-- IMPORTANT: In TFS 1.x, damage values are negative (e.g., -50),
-- so math.floor scales negative values downward more effectively.
primaryDamage = math.floor(primaryDamage * multiplier)
secondaryDamage = math.floor(secondaryDamage * multiplier)
if mode == FIGHTMODE_ATTACK and math.random(1, 100) <= 20 then
self:say("BOOM!", TALKTYPE_MONSTER_SAY)
self:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
end
end
end
-- KEY ELEMENT: You must return these values to the engine!
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
-- 2. HEALING AND DEFENSE MODIFICATION (When the player is the target)
if self:isPlayer() then
local mode = self:getFightMode()
-- Healing bonus while on Full Defense (primaryDamage > 0)
if mode == FIGHTMODE_DEFENSE and primaryDamage > 0 then
primaryDamage = math.ceil(primaryDamage * 1.25) -- +25% healing
if math.random(1, 100) <= 30 then
self:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
end
end
-- BLOCK! effect while on Full Defense (primaryDamage < 0)
if mode == FIGHTMODE_DEFENSE and primaryDamage < 0 then
if math.random(1, 100) <= 25 then
self:say("BLOCK!", TALKTYPE_MONSTER_SAY)
self:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
end
end
end
-- Standard engine handling
if hasEventCallback(EVENT_CALLBACK_ONHEALTHCHANGE) then
return EventCallback(EVENT_CALLBACK_ONHEALTHCHANGE, self, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
else
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
and works only more healing when put full defense.
Can someone knows how to do it to work?
Maybe add somethink in data/scripts?
Best regards!