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

I know nothing
TFS Developer
Joined
May 30, 2009
Messages
8,112
Solutions
218
Reaction score
4,027
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,810
Solutions
432
Reaction score
3,946
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,873
Solutions
37
Reaction score
1,093
Location
Germany
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)

tested it
doesnt work for me :X
no errors
 

Levi999x

AoT
Joined
Dec 14, 2017
Messages
1,873
Solutions
37
Reaction score
1,093
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,810
Solutions
432
Reaction score
3,946
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,873
Solutions
37
Reaction score
1,093
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,810
Solutions
432
Reaction score
3,946
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,873
Solutions
37
Reaction score
1,093
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
OP
U

UnLucky

New Member
Joined
Jul 15, 2021
Messages
36
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,810
Solutions
432
Reaction score
3,946
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
 
OP
OP
U

UnLucky

New Member
Joined
Jul 15, 2021
Messages
36
Reaction score
1
GitHub
UnLucky
@Xikini
I need your help!. The script was working perfectly and suddenly it stopped working, any ideas why?
Gyazo (https://gyazo.com/ce5d00fe83fc993193b6011a36cc1dd3) Gyazo from the server.

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
 
Last edited:

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,810
Solutions
432
Reaction score
3,946
@Xikini
I need your help!. The script was working perfectly and suddenly it stopped working, any ideas why?
Gyazo (https://gyazo.com/ce5d00fe83fc993193b6011a36cc1dd3) Gyazo from the server.

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
Yeah.. my solution above was a bandaid solution, and was doomed to failed.
Once it went past 1 week, the milliseconds would overlap and cause it fail.. and/or would eventually overload the database and give you a negative value.

The only real solution is to allow the database to use larger numbers.

 
Last edited:
OP
OP
U

UnLucky

New Member
Joined
Jul 15, 2021
Messages
36
Reaction score
1
GitHub
UnLucky
after such changes, I can normally use it permanently?.
or maybe I can add os.mtime to the engine somehow

I did as in the video, but it does not work, how I do it differently?
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,810
Solutions
432
Reaction score
3,946
after such changes, I can normally use it permanently?.
or maybe I can add os.mtime to the engine somehow

I did as in the video, but it does not work, how I do it differently?
tfs 1.2 already has os.mtime(), so you don't need to add it.

The setStorage and getStorage functions seem to be hard-coded to use int 32 values.. and I have no idea how to change it to 64 bit.. cuz everytime I do, it throws errors when compiling.


So let's just ignore using storages completely, I guess.

For this situation, with such a small time, we can just use a table.

Lua:
local exhaust = {}
local exhaustTime = 2000

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local playerId = player:getId()
    local currentTime = os.mtime()
    if exhaust[playerId] and exhaust[playerId] > currentTime then
        player:sendCancelMessage("This rune is still on cooldown. (MS:" .. exhaust[playerId] - currentTime .. ")")
        return true
    end
    
    targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        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)
    
    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)
    exhaust[playerId] = currentTime + exhaustTime
    return true
end
 
Top