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

[tfs 1.2] Global storage for specific time

tejdi

The legend never die.
Joined
Oct 26, 2010
Messages
345
Solutions
1
Reaction score
48
Location
Poland
I would like to allow action only once per X time for a whole server (10 min for example), how could I do this?

Scheme:
Lua:
local config = {
    monsterPos = {x=790, y=978, z=11},
    exhaust = X -- ??
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if game world storage = 5003, 1 then -- ??
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Error msg")
    else
        Game.createMonster("Duan", config.monsterPos)
        set game world storage = 5003, 1 for 10 min -- ??
    end
return true
end
 
Solution
I would like to allow action only once per X time for a whole server (10 min for example), how could I do this?

Scheme:
Lua:
local config = {
    monsterPos = {x=790, y=978, z=11},
    exhaust = X -- ??
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if game world storage = 5003, 1 then -- ??
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Error msg")
    else
        Game.createMonster("Duan", config.monsterPos)
        set game world storage = 5003, 1 for 10 min -- ??
    end
return true
end
Lua:
local config = {
    monsterPos = Position(790, 978, 11),
    minutes = 10
}

duanExhausted = false

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

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,629
Solutions
559
Reaction score
3,834
I would like to allow action only once per X time for a whole server (10 min for example), how could I do this?

Scheme:
Lua:
local config = {
    monsterPos = {x=790, y=978, z=11},
    exhaust = X -- ??
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if game world storage = 5003, 1 then -- ??
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Error msg")
    else
        Game.createMonster("Duan", config.monsterPos)
        set game world storage = 5003, 1 for 10 min -- ??
    end
return true
end
Lua:
local config = {
    monsterPos = Position(790, 978, 11),
    minutes = 10
}

duanExhausted = false

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if duanExhaust then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Error msg")
    else
        Game.createMonster("Duan", config.monsterPos)
        duanExhausted = true
        addEvent(function()
            duanExhausted = false -- reset exhaust
        end, 60000 * config.minutes)
    end
    return true
end
 
Solution
OP
OP
tejdi

tejdi

The legend never die.
Joined
Oct 26, 2010
Messages
345
Solutions
1
Reaction score
48
Location
Poland
Lua:
local config = {
    monsterPos = Position(790, 978, 11),
    minutes = 10
}

duanExhausted = false

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if duanExhaust then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Error msg")
    else
        Game.createMonster("Duan", config.monsterPos)
        duanExhausted = true
        addEvent(function()
            duanExhausted = false -- reset exhaust
        end, 60000 * config.minutes)
    end
    return true
end

You are amazing in helping out our community, but I would like to know more about the script (understanding will help me and maybe also others to produce their script without help)

How does this work:
if duanExhaust then...

when duanExhaust on this stage is "false" right?
I do not understand how it process when it is like 1=1 to this:

If false then...

btw. It actually does not work, I can spam right click and it will respawn a lot of monsters. No bugs in console.
 
Last edited:

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,629
Solutions
559
Reaction score
3,834
You are amazing in helping out our community, but I would like to know more about the script (understanding will help me and maybe also others to produce their script without help)

How does this work:
if duanExhaust then...

when duanExhaust on this stage is "false" right?
I do not understand how it process when it is like 1=1 to this:

If false then...

btw. It actually does not work, I can spam right click and it will respawn a lot of monsters. No bugs in console.
My bad, the variable I intended to check for is incorrectly named, so it will not matter what duanExhausted is set to.
Added some comments so you can know what's going on here. You can think of duanExhaust as a sort of switch, turning it on and off between false and true.
Lua:
local config = {
    monsterPos = Position(790, 978, 11),
    minutes = 10
}

duanExhausted = false -- acts as a "switch", true = don't spawn, false = spawn

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if duanExhausted then
        -- duanExhausted is true, do not spawn it again until the addEvent resets the "switch"
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Error msg")
    else
        Game.createMonster("Duan", config.monsterPos)
        duanExhausted = true -- now that this is true, "if duanExhausted then" will execute since the condition (duanExhausted) evaluates to true
        addEvent(function() -- this function will be called after the minutes specified in config
            duanExhausted = false -- reset exhaust switch, next time this runs duanExhausted is false and will spawn again
        end, 60000 * config.minutes)
    end
    return true
end
 
Top