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

Exhaust in manarune that will be taken from ('timeBetweenExActions') TFS 1.2

UnLucky

New Member
Joined
Jul 15, 2021
Messages
25
Reaction score
1
GitHub
UnLucky
I need an exhaust in manarune that will be taken from ('timeBetweenExActions').

TFS 1.2

I need have in config :
-- Item Usage
timeBetweenActions = 0
timeBetweenExActions = 0

but maybe Its possible to add ('timeBetweenExActions') to lua? for manarune.Lua?.

Lua:
local exhaust = Condition(CONDITION_EXHAUST)
exhaust:setParameter(CONDITION_PARAM_TICKS, getConfigInfo('timeBetweenExActions') + 1000) -- Here you can put your exhaust as you want. ( 1000 means = 1 second )

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
 
    local level = player:getLevel()
    local magLevel = player:getMagicLevel()
    local min = (level * 1) + (magLevel * 1) -- for every level you heal 1 mana more so if you setup 10 you'll heal for every level 10 mana more / same for magic level.
    local max = (level * 1) + (magLevel * 1)
    local mana_add = math.random(min,max)

    targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end

    local pos = targetPlayer:getPosition()
 
    if player:getCondition(CONDITION_EXHAUST) then
       player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_YOUAREEXHAUSTED))
       return true
    end

    targetPlayer:addMana(mana_add)

    -- This part allows you to heal with animated text even without source edits or custom client.
    local spectators = Game.getSpectators(pos, false, false, 13, 13, 7, 7)
    if #spectators > 0 then
        for i = 1, #spectators do
            local spectator = spectators[i]
            if spectator:isPlayer() then
                spectator:sendTextMessage(MESSAGE_HEALED, nil, pos, mana_add, TEXTCOLOR_YELLOW) -- <-- There you can change the color as you want.
            end
        end
    end
   
    pos:sendMagicEffect(CONST_ME_MAGIC_RED)
    targetPlayer:addCondition(exhaust)
    return true
end
 

Evil Puncker

prolonged absenteeism
TFS Developer
Joined
May 30, 2009
Messages
7,907
Solutions
197
Reaction score
3,723
why not simply use an storage to set the exhausted? or is it lower than the config.lua option?

something like this:

Lua:
    if player:getStorageValue(121212) >= os.time() then
        player:sendCancelMessage("You are exhausted.")
        return false
    end
    player:setStorageValue(121212, os.time() + 3)
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,524
Solutions
379
Reaction score
3,642
why not simply use an storage to set the exhausted? or is it lower than the config.lua option?

something like this:

Lua:
    if player:getStorageValue(121212) >= os.time() then
        player:sendCancelMessage("You are exhausted.")
        return false
    end
    player:setStorageValue(121212, os.time() + 3)
I just need to do this with ('timeBetweenExActions') so please help. with storage value set to 1s. i get duplicate and mana rune is use 2x at the same time
Change it to os.mtime() instead then.
Lua:
if player:getStorageValue(121212) >= os.mtime() then
    player:sendCancelMessage("You are exhausted.")
    return false
end
player:setStorageValue(121212, os.mtime() + 3000)
 

Levi999x

AoT
Joined
Dec 14, 2017
Messages
1,687
Solutions
32
Reaction score
924
Location
Germany
Show the script with the modifications, please.

Lua:
local manarune = Action()

function manarune.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if player:getStorageValue(52523) >= os.mtime() then
        player:sendCancelMessage("You cant use it now")
        return true
    end
 
    local targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end
 
    local pos = targetPlayer:getPosition()
    local mana_add = 100000
    player:setStorageValue(52523, os.mtime() + 5000)
    targetPlayer:addMana(mana_add)
    pos:sendMagicEffect(117)
    Game.sendAnimatedText('+'..mana_add..'', pos, 59)
    return true
end

manarune:id(2270)
manarune:register()
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,524
Solutions
379
Reaction score
3,642
Lua:
local manarune = Action()

function manarune.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if player:getStorageValue(52523) >= os.mtime() then
        player:sendCancelMessage("You cant use it now")
        return true
    end
 
    local targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end
 
    local pos = targetPlayer:getPosition()
    local mana_add = 100000
    player:setStorageValue(52523, os.mtime() + 5000)
    targetPlayer:addMana(mana_add)
    pos:sendMagicEffect(117)
    Game.sendAnimatedText('+'..mana_add..'', pos, 59)
    return true
end

manarune:id(2270)
manarune:register()
Wow, that's super annoying.

os.mtime() is a larger integer then the default storage value allows in the database.

here's a quick work-around.
Lua:
local actions_test_script = Action()

local function getCustomTime()
	return os.mtime() - 1631000000000
end

function actions_test_script.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(52523) >= getCustomTime() then
        player:sendCancelMessage("You cant use it now")
        return true
    end
 
    local targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end
 
    local pos = targetPlayer:getPosition()
    local mana_add = 100000
    player:setStorageValue(52523, getCustomTime() + 5000)
    targetPlayer:addMana(mana_add)
    pos:sendMagicEffect(117)
    Game.sendAnimatedText('+'..mana_add..'', pos, 59)
    return true
end

actions_test_script:id(2270)
actions_test_script:register()
 

Levi999x

AoT
Joined
Dec 14, 2017
Messages
1,687
Solutions
32
Reaction score
924
Location
Germany
Wow, that's super annoying.

os.mtime() is a larger integer then the default storage value allows in the database.

here's a quick work-around.
Lua:
local actions_test_script = Action()

local function getCustomTime()
    return os.mtime() - 1631000000000
end

function actions_test_script.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(52523) >= getCustomTime() then
        player:sendCancelMessage("You cant use it now")
        return true
    end
 
    local targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end
 
    local pos = targetPlayer:getPosition()
    local mana_add = 100000
    player:setStorageValue(52523, getCustomTime() + 5000)
    targetPlayer:addMana(mana_add)
    pos:sendMagicEffect(117)
    Game.sendAnimatedText('+'..mana_add..'', pos, 59)
    return true
end

actions_test_script:id(2270)
actions_test_script:register()

What would be the easiest solution avoid using local function on every script?
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,524
Solutions
379
Reaction score
3,642
What would be the easiest solution avoid using local function on every script?
You have 2 options.

Change your storage max int value in the database to accomodate higher numbers
or

Make it a global function, so you can call it anywhere.

data/lib/core/core.lua
Lua:
dofile('data/lib/core/customFunctions.lua')

Then make a new lua file called customFunctions.lua in the data/lib/core/ directory.
and paste the function inside, without the local.
Lua:
function getCustomTime()
	return os.mtime() - 1631000000000
end
 

Levi999x

AoT
Joined
Dec 14, 2017
Messages
1,687
Solutions
32
Reaction score
924
Location
Germany
You have 2 options.

Change your storage max int value in the database to accomodate higher numbers
or

Make it a global function, so you can call it anywhere.

data/lib/core/core.lua
Lua:
dofile('data/lib/core/customFunctions.lua')

Then make a new lua file called customFunctions.lua in the data/lib/core/ directory.
and paste the function inside, without the local.
Lua:
function getCustomTime()
    return os.mtime() - 1631000000000
end

Simple

Thanks
 
OP
U

UnLucky

New Member
Joined
Jul 15, 2021
Messages
25
Reaction score
1
GitHub
UnLucky
Wow, that's super annoying.

os.mtime() is a larger integer then the default storage value allows in the database.

here's a quick work-around.
Lua:
local actions_test_script = Action()

local function getCustomTime()
    return os.mtime() - 1631000000000
end

function actions_test_script.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(52523) >= getCustomTime() then
        player:sendCancelMessage("You cant use it now")
        return true
    end
 
    local targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end
 
    local pos = targetPlayer:getPosition()
    local mana_add = 100000
    player:setStorageValue(52523, getCustomTime() + 5000)
    targetPlayer:addMana(mana_add)
    pos:sendMagicEffect(117)
    Game.sendAnimatedText('+'..mana_add..'', pos, 59)
    return true
end

actions_test_script:id(2270)
actions_test_script:register()

Console Print :
Lua Script Error: [Test Interface]
data/actions/scripts/other/mana1.lua
data/actions/scripts/other/mana1.lua:1: attempt to call global 'Action' (a nil value)
stack traceback:
[C]: in function 'Action'
data/actions/scripts/other/mana1.lua:1: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/other/mana1.lua
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,524
Solutions
379
Reaction score
3,642
Console Print :
Lua Script Error: [Test Interface]
data/actions/scripts/other/mana1.lua
data/actions/scripts/other/mana1.lua:1: attempt to call global 'Action' (a nil value)
stack traceback:
[C]: in function 'Action'
data/actions/scripts/other/mana1.lua:1: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/other/mana1.lua
His is a different script for TFS 1.3

Here is yours.
Lua:
local storage = 45000
local cooldown = 2000 -- milliseconds

local function getCustomTime()
    return os.mtime() - 1631000000000
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(storage) >= getCustomTime() then
        player:sendCancelMessage("You cant use it now")
        return true
    end
    
    local level = player:getLevel()
    local magLevel = player:getMagicLevel()
    local min = (level * 1) + (magLevel * 1) -- for every level you heal 1 mana more so if you setup 10 you'll heal for every level 10 mana more / same for magic level.
    local max = (level * 1) + (magLevel * 1)
    local mana_add = math.random(min,max)
    
    targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end
    
    local pos = targetPlayer:getPosition()    
    targetPlayer:addMana(mana_add)
    
    -- This part allows you to heal with animated text even without source edits or custom client.
    local spectators = Game.getSpectators(pos, false, false, 13, 13, 7, 7)
    if #spectators > 0 then
        for i = 1, #spectators do
            local spectator = spectators[i]
            if spectator:isPlayer() then
                spectator:sendTextMessage(MESSAGE_HEALED, nil, pos, mana_add, TEXTCOLOR_YELLOW) -- <-- There you can change the color as you want.
            end
        end
    end
    
    pos:sendMagicEffect(CONST_ME_MAGIC_RED)
    player:setStorageValue(storage, getCustomTime() + cooldown)
    return true
end
 
Top