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

CreatureEvent Passive Spells tfs 1.2

why u are all saying it dont work?

i have the script inside my game and it clearly does this extra attack every 5 seconds... just need fix lagg somnehow

why it wouldnnt work? it clearly works ingame...
 
I thought that after "if cooldowna ~= nil then" part there is "elseif" instead of "if" but yes it should work my bad.
Here is slightly better code:
Code:
function onThink(creature, interval)
    if(creature:isPlayer()) then
        local target = creature:getTarget()
        if(target and creature:getStorageValue(7608) == 2) then
            local cooldown = math.max(0, creature:getStorageValue(23157))
            if(cooldown >= 5000) then
                creature:setStorageValue(23157, cooldown - 5000)

                local targetPos = target:getPosition()
                if(creature:getPosition():isSightClear(targetPos)) then
                    local level = creature:getLevel()
                    Position(targetPos.x - 6, targetPos.y - 5, targetPos.z):sendDistanceEffect(targetPos, 34)
                    doTargetCombatHealth(creature, target, COMBAT_FIREDAMAGE, -(level * 1.5 * 0.7), -(level * 2 * 0.8), CONST_ME_FIREAREA)
                end
            else
                creature:setStorageValue(23157, cooldown + interval)
            end
        end
    end

    return true
end
As to why it's lagging the reason might be actually using storages for this, since keys are stored in binary tree it might get heavy on the CPU if you have a lot of players and storages stored(especially on slower CPU's).
But the lagging might be because of some others scripts, are you 100% sure this cause the lags?
 
yes this caused lagg on my server the same day people got this storage value, it lasted for around 3 days and i modified script abit everyday (but after 3 days i removed it ) to see if it got better but it always ended up causing laggs so i removed this but i want to add it again but idk how to fix

and when i removed it there was never this laggs again. my idea is to make it into onhealthchange script instead if i cant fix with onthink

but yeah i agree its really weird why its causing laggs, and its hard to check if it causes lagg because all my players are now quitted
 
Last edited by a moderator:
Okay one way to avoid calling the whole OnThink function is to add a check for the time with this:

above function OnThink()
Lua:
local check_interval = 10 -- Edit this
local check_clock = os.clock()

then right after the function OnThink() starts add
Lua:
if (os.clock() - check_clock) > check_interval then 
    -- whole code
end

I think that the interval in this case would be every 10 seconds.
This will still be called every {interval} ms, but will not do any of the whole code unless the interval of the os.clock has passed.
This might reduce the lag, but not avoid any problems in the code making it lag.
Danat
 
The min max values could be summarized by 1 simple method
Lua:
function minMax(l, m, v, a)
    if isInArray({1, 2}, v) then
        return -((l / 5) + (m * 1.4) + 8), -((l / 5) + (m * 2.2) + 14)
    elseif v == 3 then
        return -((l / 5) + m * 2), -((l / 5) + m * 5)
    end
    return -((l / 5) + (m * a * 0.01) + 1), -((l / 5) + (m * a * 0.03) + 6)
end
l being level, m could be passed skilllvl or maglevel, v is the vocation & a is the attack.

id is kind of a useless property to have since it's a straight up table with no indexes, just the default, I mean if you wanted to be explicit about it you could do something like this.
Lua:
local voc = {
    [1] = { -- sorc
        spellname = "passive spell", --TODO think for proper names
        combatDamage = COMBAT_DEATHDAMAGE,
        CombatEffect = CONST_ME_MORTAREA,
        distEffect = CONST_ANI_DEATH
    },
    [2] = { -- druid
        spellname = "passive spell",
        combatDamage = COMBAT_ICEDAMAGE,
        CombatEffect = CONST_ME_ICEAREA,
        distEffect = CONST_ANI_ICE
    },
    [3] = { -- pally
        spellname = "passive spell",
        combatDamage = COMBAT_PHYSICALDAMAGE,
        CombatEffect = CONST_ME_HITAREA,
        distEffect = CONST_ANI_THROWINGSTAR
    },
    [4] = { -- knight
        spellname = "passive spell",
        combatDamage = COMBAT_PHYSICALDAMAGE,
        CombatEffect = CONST_ME_DRAWBLOOD,
        distEffect = CONST_ANI_LARGEROCK
    },
}
You also don't need the for loop in their especially since you can access the vocations through its index with or without stating which index is what.

If you want you also index the weapon type using a table
Lua:
local weaponTypes = {
    [0] = { 0, 0 }, -- fist
          { 1, 2 }, -- Sword
          { 2, 1 }, -- Club
          { 3, 3 }, -- Axe
          { 4, 5 }, -- Shield
          { 5, 4 }, -- Distance
          { 6, 0 } -- 6 is rod / wands, 0 is for fists..
}
 
Hello, I have a problem. I am using placed code and errors occurred.

[screenlog]

Lua Script Error: [CreatureScript Interface] data/creaturescripts/scripts/passive.lua:onThink data/creaturescripts/scripts/passive.lua:87: attempt to call global 'getItemAttribute' (a nil value) stack traceback: [C]: in function 'getItemAttribute' data/creaturescripts/scripts/passive.lua:87: in function <data/creaturescripts/scripts/passive.lua:48>

I use TFS 1.2
 
Back
Top