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

TFS 1.X+ [TFS 1.2] Critical System some questions!!!

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...
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
 
You are doing some calculations mostly, there is no way this is going to burn your CPU or eat memory.
What's mostly burn CPU and RAM? Creaturescripts, globalevent oraz maybe my customs Spells.
I see little lags if i Attack many monster.
I have too slot loot system, each Item drop other stats.
 
Maybe this sample of my Spells can laggy server?




function spellCallbackStorm3(cid, position, count)
local origin = Position(position.x - 6, position.y - 6, position.z)
if Creature(cid) then
if math.random(1, 30) == 1 then
position:sendMagicEffect(4)
origin:sendDistanceEffect(position, math.random(22, 24))
end
if count < 1 then
count = count + 1
addEvent(spellCallbackStorm3, math.random(100, 333), cid, position, count)
end
end
end

function onTargetTile(creature, position)
spellCallbackStorm3(creature:getId(), position, 0)
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setArea(createCombatArea(AREA_CIRCLE4X4))
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, true)

function onGetFormulaValues(player, skill, attack, factor)
local axeSkill = player:getEffectiveSkillLevel(SKILL_AXE)
local lvl = player:getLevel()
local mlvl = player:getMagicLevel() * 5
local adddamage6 = player:getStorageValue(272123) + 1
local onelvl6 = player:getStorageValue(172123) + 1
local promotionS = player:getStorageValue(520123) + 1
local reb = player:getStorageValue(720123) + 1
local u1 = player:getStorageValue(8000) * (((lvl * 2) + ((axeSkill * attack) / 3) + (mlvl * 15) + adddamage6 + onelvl6 + reb + promotionS) * 0.01)


local min = ((lvl * 2) + ((axeSkill * attack) / 3) + (mlvl * 15) + adddamage6 + u1 + onelvl6 + reb + promotionS) / 6
local max = ((lvl * 2) + ((axeSkill * attack) / 3) + (mlvl * 15) + adddamage6 + u1 + onelvl6 + reb + promotionS) / 6
player:addSkillTries(SKILL_AXE, 3)
return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")


function onCastSpell(creature, var, isHotkey)
if creature:getStorageValue(5086868) >= 1 then
combat:execute(creature, var)
for i = 1, 5 do
addEvent(function() combat:execute(creature, var) end, i * 333)
end
else
creature:sendTextMessage(MESSAGE_INFO_DESCR, "You Reborn Level is too low. Requires 1 or higher.")
end
return true
end
 
Back
Top