• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Speed Change

marcos16

Falkhonn
Joined
May 4, 2012
Messages
224
Reaction score
1
I am using a script to change speed. But when a player moves from level with the effect of any speed magic happens the following: Ex: Level 300 with speed 380 uses run magic is about 450 but the speed of advance level [with yet activated hur] back to speed 400 [which is level of speed 301+] When the effect ends hur back to speed 330. One could modify to do this?

Below the script:

Code:
local info = {
[{10, 49}] = {speed = 250},
[{50, 100}] = {speed = 290},
[{101, 149}] = {speed = 340},
[{150, 249}] = {speed = 360},
[{250, 300}] = {speed = 380},
[{301, 4000}] = {speed = 400}
}

function onAdvance(cid, skill, oldLevel, newLevel)
    for level, x in pairs(info) do
         if skill == 8 and newLevel >= level[1] and newLevel <= level[2] then
            doChangeSpeed(cid, -getCreatureSpeed(cid))
       doChangeSpeed(cid, x.speed)
        end
    end
return 1
end
 
You should really be using conditions for this.
Code:
local info = {
[{10, 49}] = 1, -- subId, also act as a multiplier
[{50, 100}] = 2,
[{101, 149}] = 3,
[{150, 249}] = 4,
[{250, 300}] = 5,
[{301, 4000}] = 6
}
local condition = {}
for levelRange, subId in ipairs(info) do
    -- createConditionObject(type, duration (-1 means forever or until removed), buff, subId)
    condition[levelRange] = createConditionObject(CONDITION_HASTE, -1, false, subId)
    -- setConditionFormula(condition, 0.3, -24, 0.3, -24) -- haste base formula
    condition[levelRange] = setConditionFormula(condition[levelRange], (0.3 + (subId * 0.1)), (-24 * subId), (0.3 + (subId * 0.1)), (-24 * subId))
end

function sizeOf(t)
    local c = 0
    if next(t) then
        for i in pairs(t) do
            c = c + 1
        end
    end
    return c
end

function onAdvance(cid, skill, oldLevel, newLevel)
    for level, x in pairs(info) do
         if skill == 8 then
            if newLevel >= level[1] and newLevel <= level[2] then
            -- hasCondition(cid, condition[, subId])
                for i = 1, sizeOf(info) do
                    if hasCondition(cid, CONDITION_HASTE, i) then
                        doRemoveCondition(cid, CONDITION_HASTE, i)
                    end
                end
                doAddCondition(cid, condition[level])
            end
        end
    end
    return true
end
 
Last edited:
This is another variation in case you decide to change the values in the info table.
Code:
local info = {
    [{10, 49}] = 1, -- subId, also act as a multiplier
    [{50, 100}] = 2,
    [{101, 149}] = 3,
    [{150, 249}] = 4,
    [{250, 300}] = 5,
    [{301, 4000}] = 6
}

local condition = {}

for levelRange, subId in ipairs(info) do
    -- createConditionObject(type, duration (-1 means forever or until removed), buff, subId)
    condition[levelRange] = createConditionObject(CONDITION_HASTE, -1, false, subId)
    -- setConditionFormula(condition, 0.3, -24, 0.3, -24) -- haste base formula
    condition[levelRange] = setConditionFormula(condition[levelRange], (0.3 + (subId * 0.1)), (-24 * subId), (0.3 + (subId * 0.1)), (-24 * subId))
end

function onAdvance(cid, skill, oldLevel, newLevel)
    for level in pairs(info) do
         if skill == 8 then
            if newLevel >= level[1] and newLevel <= level[2] then
            -- hasCondition(cid, condition[, subId])
                for _, subid in ipairs(info) do
                    if hasCondition(cid, CONDITION_HASTE, subid) then
                        doRemoveCondition(cid, CONDITION_HASTE, subid)
                    end
                end
                doAddCondition(cid, condition[level])
            end
        end
    end
    return true
end
 
Back
Top