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

Help with Haste.lua

gubbo123

New Member
Joined
Aug 15, 2017
Messages
151
Solutions
1
Reaction score
3
LUA:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_HASTE)
condition:setParameter(CONDITION_PARAM_TICKS, 33000)
condition:setFormula(0.3, -24, 0.3, -24)
combat:setCondition(condition)

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

how modific this script to work to depend of level?
example: level 10 x speed, lvl 20 x speed, level 30 x speed?

condition:setFormula(0.3, -24, 0.3, -24) i don't understand this numbers, what of these numbers represents more speed value?
 
LUA:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_HASTE)
condition:setParameter(CONDITION_PARAM_TICKS, 33000)
condition:setFormula(0.3, -24, 0.3, -24)
combat:setCondition(condition)

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

how modific this script to work to depend of level?
example: level 10 x speed, lvl 20 x speed, level 30 x speed?

condition:setFormula(0.3, -24, 0.3, -24) i don't understand this numbers, what of these numbers represents more speed value?
What you want it happens pretty much by default this is your speed formula that multiplies with your level. If im wrong someone correct me.
 
LUA:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_HASTE)
condition:setParameter(CONDITION_PARAM_TICKS, 33000)
condition:setFormula(0.3, -24, 0.3, -24)
combat:setCondition(condition)

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

how modific this script to work to depend of level?
example: level 10 x speed, lvl 20 x speed, level 30 x speed?

condition:setFormula(0.3, -24, 0.3, -24) i don't understand this numbers, what of these numbers represents more speed value?
Condition formulas are handled like this:
LUA:
condition:setFormula(mina, minb, maxa, maxb)
C++:
    min = (var * mina) + minb;
    max = (var * maxa) + maxb;
As you can see here:
otland/forgottenserver (https://github.com/otland/forgottenserver/blob/c7bef1519a5040eb82d4923005602b0e026f7d96/src/condition.cpp#L1314)

In this case var = players base speed.

So this is basically what that formula function is doing:
C++:
min = (base_speed * 0.3) + -24
max = (base_speed * 0.3) + -24

And considering that this is less than the base speed it must later add this amount to the existing players speed. At least that's what I understand out of it.

That said moving the conditions inside the onCastSpell function and using level to manipulate the formula inside would be best:
LUA:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onCastSpell(creature, variant)
    local level = creature:getLevel()
    local condition = Condition(CONDITION_HASTE)
    condition:setParameter(CONDITION_PARAM_TICKS, 33000)
    condition:setFormula(0.3 + level, -24 + level, 0.3 + level, -24 + level)
    combat:setCondition(condition)
    return combat:execute(creature, variant)
end

Obviously this will probably not be how you want the formula to be but it is so you can understand the general idea.
 
Last edited:
one way simple is:
Code:
function onCastSpell(player, variant)

    local mana = 60
    if player:getMana() < mana then
        player:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    player:addMana(-mana)
    player:addManaSpent(mana)

    local condition = Condition(CONDITION_HASTE)
    condition:setParameter(CONDITION_PARAM_TICKS, 33000)
    local speed = math.ceil(player:getLevel() * 0.1)
    condition:setParameter(CONDITION_PARAM_SPEED, math.max(speed, 10))
    player:addCondition(condition)

    return true
end
 
Back
Top