• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[8.6] [OTX] Simple summon rune request

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,759
Solutions
31
Reaction score
999
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
I need a rune or a wooden flute (id:2070) that when use it summons a maxium of 6 snake on the selected tile (with a cooldown of 10 minutes). The main idea of this is to have snakes for training with a summoned monk, avoiding the lure.
 
Last edited:
Solution
So we can re-write this as
LUA:
local minutes, storage = 10, 555

function getExhaustTime()
  return tonumber(os.date("%H%M", os.time()+(minutes*60)))
end

function getCurrentTime()
  return tonumber(os.date("%H%M", os.time()))
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if getPlayerStorageValue(player,storage) < getCurrentTime()  then
        doSendAnimatedText(fromPosition, "You must wait "..(minutes).." minutes before using this item again.", MESSAGE_INFO_DESCR])
        return false
    else
        for i=1,6 do
            doCreatureMonster('Snake',getCreaturePosition(player))
        end
        setPlayerStorageValue(player,storage, getExhaustTime())
    end
    return true
end
If you need...
What do you mean by 'on the selected tile'?
LUA:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storage = 555
    local cooldown = 10*60*1000 -- ten minutes
    if getPlayerStorageValue(player,storage) == 1 then
        doSendAnimatedText(fromPosition, "You must wait 10 minutes before using this item again.", MESSAGE_INFO_DESCR])
    else
        for i=1,6 do
            doCreatureMonster('Snake',getCreaturePosition(player))
        end
        setPlayerStorageValue(player,storage,1)
        addEvent(function()
        setPlayerStorageValue(player,storage,0)
        end,cooldown)
    end
    return true
end
in actions will do what you want.
 
Instead of using addEvents you could use a function which will set the storage value as the current time + 10 minutes.
LUA:
local minutes = 10
function getTime()
  return tonumber(os.date("%H%M", os.time()+(minutes*60)))
end

function getCurrentTime()
  return tonumber(os.date("%H%M", os.time()))
end

print(getTime(), getCurrentTime(), getTime() == getCurrentTime(), type(getTime()), type(getCurrentTime()))
Here you can see how the function behaves.
LUA:
1625    1615    false    number    number
 
So we can re-write this as
LUA:
local minutes, storage = 10, 555

function getExhaustTime()
  return tonumber(os.date("%H%M", os.time()+(minutes*60)))
end

function getCurrentTime()
  return tonumber(os.date("%H%M", os.time()))
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if getPlayerStorageValue(player,storage) < getCurrentTime()  then
        doSendAnimatedText(fromPosition, "You must wait "..(minutes).." minutes before using this item again.", MESSAGE_INFO_DESCR])
        return false
    else
        for i=1,6 do
            doCreatureMonster('Snake',getCreaturePosition(player))
        end
        setPlayerStorageValue(player,storage, getExhaustTime())
    end
    return true
end
If you need more precision you can always add more arguments to os.date()
Programming in Lua : 22.1
 
Last edited:
Solution
Back
Top