• 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() -...
<instant group="attack" spellid="61" name="Brutal Strike" words="exori ico" lvl="16" mana="30" prem="1" range="1" needtarget="1" needweapon="1" cooldown="6000" groupcooldown="2000" needlearn="0" script="attack/brutal strike.lua"/>
 
<instant group="attack" spellid="61" name="Brutal Strike" words="exori ico" lvl="16" mana="30" prem="1" range="1" needtarget="1" needweapon="1" cooldown="6000" groupcooldown="2000" needlearn="0" script="attack/brutal strike.lua"/>

What I'm saying it's when you use the spell, you will have a time of 2 seconds, then the spell will be casted. And not 2 seconds of cooldown. I'm trying to put this formula on my script.
 
Code:
local function executeSpell(cid, variant)
    local creature = Creature(cid)
    if not creature then
        return true
    end

    combat:execute(creature, variant)
end

function onCastSpell(creature, variant)
    addEvent(executeSpell, 2 * 1000, creature.uid, variant)
    return true
end
 
Last edited:
<instant group="attack" spellid="61" name="Brutal Strike" words="exori ico" lvl="16" mana="30" prem="1" range="1" needtarget="1" needweapon="1" cooldown="6000" groupcooldown="2000" needlearn="0" script="attack/brutal strike.lua"/>

What he wants is a spell that will be executed after two seconds after the player casted it and not a cooldown/cooldowngroup.

Sorry, the page didn't refreshed.

You should use
Code:
function onCastSpell(creature, variant)
    addEvent(Combat.execute, 2 * 1000, combat, creature:getId(), variant)
    return true
end
 
What he wants is a spell that will be executed after two seconds after the player casted it and not a cooldown/cooldowngroup.

Sorry, the page didn't refreshed.

You should use
Code:
function onCastSpell(creature, variant)
    addEvent(Combat.execute, 2 * 1000, combat, creature:getId(), variant)
    return true
end
This will probably crash the server, if creature is nil at time when spell executes.
 
Code:
addEvent(function() combat:execute(creature, variant) end, 2 * 1000)

What he wants is a spell that will be executed after two seconds after the player casted it and not a cooldown/cooldowngroup.

Sorry, the page didn't refreshed.

You should use
Code:
function onCastSpell(creature, variant)
    addEvent(Combat.execute, 2 * 1000, combat, creature:getId(), variant)
    return true
end

It worked perfectly !! If I wanted to put a exhaust after say the spell, like 4 seconds, could this be done? For only this spell I mean
 
Yes can be if he got removed somehow, for example died?

Yes, you are right! Thanks I didn't saw in that way. Also, I think that should pass the values of combat, creature:getId() and variant to the local function executeSpell.

For example like this:
Code:
local function executeSpell(combat, creatureId, variant)
    local creature = Creature(creatureId)
    if not creature then
        return true
    end

    combat:execute(creature, variant)
end

function onCastSpell(creature, variant)
    addEvent(executeSpell, 2 * 1000, combat, creature:getId(), variant)
    return true
end
 
The creature can't/won't be nil if it is a player. How the player can cast a spell and be nil at the same time? xD

That only happens with monster spells.
Thanks!! How I said, if I wanted to put a exhaust after say the spell, like 4 seconds, could this be done? For only this spell. This is correct? If it's correct, what I change to put the "4 seconds"?

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, level, maglevel)
    local min = (level / 5) + (maglevel * 0.2) + 7
    local max = (level / 5) + (maglevel * 0.85) + 16
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    addEvent(Combat.execute, 2 * 1000, combat, creature:getId(), variant)
    self:setStorageValue(value, time + os.time())
    return true
end
 
Thanks!! How I said, if I wanted to put a exhaust after say the spell, like 4 seconds, could this be done? For only this spell. This is correct? If it's correct, what I change to put the "4 seconds"?

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, level, maglevel)
    local min = (level / 5) + (maglevel * 0.2) + 7
    local max = (level / 5) + (maglevel * 0.85) + 16
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    addEvent(Combat.execute, 2 * 1000, combat, creature:getId(), variant)
    setStorageValue(value, time + os.time())
    return true
end

You should do something like this
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 6)
combat:setArea(createCombatArea(AREA_SOULFIRE))
function onGetFormulaValues(player, level, maglevel)
    local min = (level / 5) + (maglevel * 0.2) + 7
    local max = (level / 5) + (maglevel * 0.85) + 16
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

local function executeSpell(combat, creatureId, variant)
    local creature = Creature(creatureId)
    if not creature then
        return false
    end
    combat:execute(creature, variant)
    return true
end

function onCastSpell(creature, variant)
    addEvent(executeSpell, 4 * 1000, combat, creature:getId(), variant)
end

The value you can change in L25.
addEvent(executeSpell, 4 * 1000, combat, creature:getId(), variant)
 
You should do something like this
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 6)
combat:setArea(createCombatArea(AREA_SOULFIRE))
function onGetFormulaValues(player, level, maglevel)
    local min = (level / 5) + (maglevel * 0.2) + 7
    local max = (level / 5) + (maglevel * 0.85) + 16
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

local function executeSpell(combat, creatureId, variant)
    local creature = Creature(creatureId)
    if not creature then
        return false
    end
    combat:execute(creature, variant)
    return true
end

function onCastSpell(creature, variant)
    addEvent(executeSpell, 4 * 1000, combat, creature:getId(), variant)
end

The value you can change in L25.
addEvent(executeSpell, 4 * 1000, combat, creature:getId(), variant)

Yea, but that is before execute the spell, that's right already. Now what I was thinking is about to have an "exhaust" after the casting the spell, so that I can not use it multiple times in sequence

For example: I'll use the spell, will have 4 seconds to execute the spell, and I will not be able to use this spell again in those 4 seconds, before it run

I'm trying to put a exhaust after the spell is casted, but don't works. The only thing that worked, was that inadvertently, when I use magic, her name does not appear on the screen. This I wanted to happen.

@Edit: Agora que eu vi que você é brasileiro, eu consigo me expressar melhor, mas assim, eu iria usar a magia, e iria ter um tempo para ela ser lançada por exemplo 2 segundos, e desde o momento que eu usei a magia, iria ter o mesmo tempo como exaustão por exemplo 2 segundos. Ou seja, eu iria usar a magia, e iria ter uma exaustão de 2 segundos e iria demorar 2 segundos para lançar a magia. E uma coisa que eu fiz sem querer, e que eu queria, foi que quando eu uso a magia, ela não sai na tela em forma de texto, como que eu fiz isso ?

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, level, maglevel)
    local min = (level / 5) + (maglevel * 0.2) + 7
    local max = (level / 5) + (maglevel * 0.85) + 16
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    addEvent(Combat.execute, 2 * 1000, combat, creature:getId(), variant)
        if player:getExhaustion(1000) <= 0 then
            player:setExhaustion(1000, 10)
        else
            print('You\'re exhausted for: '..player:getExhaustion(1000)..' seconds.')
    return true
end
end

Gif

giphy.gif


Bump

I found a formula that gives the Exhaust that I need, but how I can put into my script ?

This is the exhaust formula:
Lua:
local storage_time_spell = 50500 -- example storage
local spell_exaust_time = 30 -- in seconds

function onCastSpell(cid, var)
if getPlayerStorageValue(cid, storage_time_spell) <= os.time() then
setPlayerStorageValue(cid, storage_time_spell, os.time() + spell_exaust_time)
return doCombat(cid, combat, var)
end
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, 'Sorry, not posible.')
end

My spell 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, level, maglevel)
    local min = (level / 5) + (maglevel * 0.2) + 7
    local max = (level / 5) + (maglevel * 0.85) + 16
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    addEvent(Combat.execute, 2 * 1000, combat, creature:getId(), variant)
    return true
end

How I can put the exhaust script on my spell ? I tried a a lot of combinations and nothing work
 
Last edited by a moderator:
Lua:
local storage_time_spell = 50500 -- example storage
local spell_exaust_time = 30 -- in seconds
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 6)
combat:setArea(createCombatArea(AREA_SOULFIRE))
function onGetFormulaValues(player, level, maglevel)
    local min = (level / 5) + (maglevel * 0.2) + 7
    local max = (level / 5) + (maglevel * 0.85) + 16
    return -min, -max
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, variant)
  if creature:getStorageValue(storage_time_spell) > os.time() then
    creature:sendCancelMessage('Sorry, not posible.')
    creature:getPosition():sendMagicEffect(CONST_ME_POFF)
  return true
  end
  addEvent(Combat.execute, 2 * 1000, combat, creature:getId(), variant)

  creature:setStorageValue(storage_time_spell, os.time() + spell_exaust_time)
return true
end
 
Lua:
local storage_time_spell = 50500 -- example storage
local spell_exaust_time = 30 -- in seconds
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 6)
combat:setArea(createCombatArea(AREA_SOULFIRE))
function onGetFormulaValues(player, level, maglevel)
    local min = (level / 5) + (maglevel * 0.2) + 7
    local max = (level / 5) + (maglevel * 0.85) + 16
    return -min, -max
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, variant)
  if creature:getStorageValue(storage_time_spell) > os.time() then
    creature:sendCancelMessage('Sorry, not posible.')
    creature:getPosition():sendMagicEffect(CONST_ME_POFF)
  return true
  end
  addEvent(Combat.execute, 2 * 1000, combat, creature:getId(), variant)

  creature:setStorageValue(storage_time_spell, os.time() + spell_exaust_time)
return true
end

This is very strange because it does not work, I only get an exhaust of 1 second :confused:
 
Check cooldown in spells.xml
Code:
    <instant group="attack" spellid="10" name="Advanced Soul Fire" words="advanced soul fire" maglv="20" mana="95" prem="0" selftarget="1" blockwalls="1" needlearn="0" script="advanced soul fire.lua">
        <vocation id="1"/>
        <vocation id="4"/>
        <vocation id="5"/>
        <vocation id="6"/>
    </instant>
If I put cooldown on XML, I'll get exhaust on all spells. But I need only a exhaust on this spell
 
Back
Top