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

Lua How to do it on a spell script ?

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
315
Solutions
1
Reaction score
58
Hello,

I'm trying to modify a script from a spell, which when it throws a spell, would take a while before executing the spell, like this:

"function onCastSpell(creature, variant)
WAIT 2 SECONDS
return combat:execute(creature, variant)
end"

and I'm using OTX Server, I found this formulas below on Lib, and would to put it inside the "WAIT 2 SECONDS", I think this is the most correct way or is there anything better?

Formulas on Lib
Lua:
function Player.setExhaustion(self, value, time)
    return self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if storage <= 0 then
        return 0
    end

    return storage - os.time()
end

This is my Script
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 6)
combat:setArea(createCombatArea(AREA_SOULFIRE))

function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end
 
Solution
Somebody?
try
Lua:
local config = {
    cooldown = 2,
    storage = 45382
}
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 40)

local area = createCombatArea(AREA_CIRCLE3X3)
combat:setArea(area)

function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, variant)
  local player = creature:getPlayer()
    if not player then
        return false
    end
    local remainingTime = (os.time() -...
cooldown="6000" is exhaust for a single spell, it will affect only your Advanced Soul Fire
set groupcooldown="0" so it wouldnt affect any other attack spells (group="attack")
 
cooldown="6000" is exhaust for a single spell, it will affect only your Advanced Soul Fire
set groupcooldown="0" so it wouldnt affect any other attack spells (group="attack")

What I'm saying is that when I use advanced soul fire, I'll be able to use other attack spells. If i put "cooldown="6000"" I'll not be able to use other attack spell :(.

Bump, I need help urgently.

Bump...

Somebody?
 
Last edited by a moderator:
Somebody?
try
Lua:
local config = {
    cooldown = 2,
    storage = 45382
}
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 40)

local area = createCombatArea(AREA_CIRCLE3X3)
combat:setArea(area)

function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, variant)
  local player = creature:getPlayer()
    if not player then
        return false
    end
    local remainingTime = (os.time() - player:getStorageValue(config.storage))
    if remainingTime < config.cooldown then
     player:sendTextMessage(MESSAGE_INFO_DESCR, "you must wait "..(config.cooldown - remainingTime).." seconds.")
    else
    player:setStorageValue(config.storage, os.time())
    addEvent(Combat.execute, 2 * 1000, combat, creature:getId(), variant)
    end
end
 
Last edited:
Solution
try
Lua:
local config = {
    cooldown = 15,
    storage = 45382
}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 6)
local area = createCombatArea(AREA_CIRCLE1X1)
combat:setArea(area)
function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, variant)
  local player = creature:getPlayer()
    if not player then
        return false
    end
    local remainingTime = (os.time() - player:getStorageValue(config.storage))
    if remainingTime < config.cooldown then
     player:sendTextMessage(MESSAGE_INFO_DESCR, "you must wait "..(config.cooldown - remainingTime).." seconds.")
    else
    player:setStorageValue(config.storage, os.time())
    return combat:execute(creature, variant)
    end
end

Bro, Thanks, you saved me a lot!!! I was breaking my head with this. :)

@Edit: But i forgot one thing, this function, to have the delay of casting time
Lua:
function onCastSpell(creature, variant)
    addEvent(Combat.execute, 2 * 1000, combat, creature:getId(), variant)
    end
 
Last edited:
Bro, Thanks, you saved me a lot!!! I was breaking my head with this. :)

@Edit: But i forgot one thing, this function, to have the delay of casting time
Lua:
function onCastSpell(creature, variant)
    addEvent(Combat.execute, 2 * 1000, combat, creature:getId(), variant)
    end
you can change
Lua:
cooldown = 15, 
to 
cooldown = 2,
 
you can change
Lua:
cooldown = 15,
to
cooldown = 2,

Yes, but this is the cooldown to use the spell again. This function that I mencioned is to charge the spell.

Example: I'll use the spell, will have the time to charge Example: 2 Seconds. and the cooldown Example: 15 seconds.

This function was charge the spell.

Like this, when I said the spell, have 2 seconds to charge and cast
giphy.gif
 
Yes, but this is the cooldown to use the spell again. This function that I mencioned is to charge the spell.

Example: I'll use the spell, will have the time to charge Example: 2 Seconds. and the cooldown Example: 15 seconds.

This function was charge the spell.

Like this, when I said the spell, have 2 seconds to charge and cast
giphy.gif
check update
 
Back
Top