Gicu
Well-Known Member
- Joined
- Feb 26, 2011
- Messages
- 187
- Reaction score
- 52
Hello i have that script, and i asked is good write. This can make problems INVISIBLE memory, CPU eating?
Maybe u have TIP for me for better custom thsi scripts.
Sorry for english i know...
Maybe u have TIP for me for better custom thsi scripts.
Sorry for english i know...
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
--If its a field or damage over time
if Tile(creature:getPosition()):hasFlag(TILESTATE_MAGICFIELD) == TRUE or attacker == nil then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
--If its not a player or monster attacking
if not attacker:isPlayer() and not attacker:isMonster() then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
--monster damage
if attacker:isMonster() then
primaryDamage = primaryDamage / 3
end
--pvp damage
if attacker:isPlayer() and not creature:isMonster() then
local pvp = (attacker:getMagicLevel() / 3) + 1
primaryDamage = primaryDamage * pvp
end
if attacker:isPlayer() and not creature:isMonster() and attacker:getStorageValue(5086868) >= 19 then
primaryDamage = primaryDamage / 6
end
local pDam, pCap = 0, 0
local dodge = false
--Calculate CRIT chance of players
if attacker:isPlayer() then
if math.random(100) < attacker:getEffectiveSkillLevel(SKILL_FISHING) / 10 then
--The chance of critical is based on the weapon type, the same for crit damage
pDam = (attacker:getEffectiveSkillLevel(SKILL_FISHING) / 150) * primaryDamage
end
end
--Calculate DODGE chance of players
if creature:isPlayer() and primaryType ~= COMBAT_HEALING then
--Get's the free % of the capacity
pCap = (creature:getEffectiveSkillLevel(SKILL_SWORD) / 10)
--The calculation is based on speed and % of free capacity (cap)
if pCap > math.random(100) then
dodge = true
creature:say("DODGE", TALKTYPE_ORANGE_1)
end
end
--If dodged
if dodge then
creature:getPosition():sendMagicEffect(3)
return primaryDamage - primaryDamage, primaryType, secondaryDamage - secondaryDamage, secondaryType
else
--If critted
if pDam ~= 0 then
local totalDMG = primaryDamage + pDam
if attacker:isPlayer() then
creature:getPosition():sendMagicEffect(173)
attacker:sendTextMessage((MESSAGE_DAMAGE_DEALT), "Critical: +".. totalDMG .." !")
return primaryDamage + pDam, primaryType, secondaryDamage, secondaryType
else
return primaryDamage + pDam, primaryType, secondaryDamage, secondaryType
end
end
--Normal damage
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
end