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

Tfs 1.2 Time Machete

lazarus321

Member
Joined
May 8, 2017
Messages
222
Reaction score
23
If i have this action for machete,
C++:
<action itemid="2420" script="tools/machete.lua" />

C++:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 2782 then
        target:transform(2781)
        target:decay()
        return true
    end
    return destroyItem(player, target, toPosition)
end

How could I put a time to use again? if it is action, I have no idea how I would do it.
 
Solution
Code:
local storage_id=0000 --storage id
local time_interval=00 --delay time

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 2782 then
        if(player:getStorageValue(storage_id)<os.time())then
          target:transform(2781)
          target:decay()
          player:setStorageValue(storage_id, os.time() + time_interval)
           return destroyItem(player, target, toPosition)
        else
          --print message here?
          return false
        end
    end
  return true
end
Code:
local storage_id=0000 --storage id
local time_interval=00 --delay time

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 2782 then
        if(player:getStorageValue(storage_id)<os.time())then
          target:transform(2781)
          target:decay()
          player:setStorageValue(storage_id, os.time() + time_interval)
           return destroyItem(player, target, toPosition)
        else
          --print message here?
          return false
        end
    end
  return true
end
 
Solution
nice, I understood now how it works. Thanks @xKrazyx.
Or you can add these funcs by printer in data/lib/core/player.lua, it's the same process as krazy's script but you can use it for other scripts as well.
LUA:
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end
 
function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end
 
    return storage - os.time()
end
 
function Player.hasExhaustion(self, value)
    return self:getExhaustion(value) > 0
end

Then do your script like this:
LUA:
local exhaust = 5000

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 2782 and not player:hasExhaustion(exhaust) then
        target:transform(2781)
        target:decay()
        player:setExhaustion(exhaust, 5) -- in seconds
        return true
    end
    return destroyItem(player, target, toPosition)
end
 
if u need to put to all items, u can put in config.lua
Code:
-- Item Usage
timeBetweenActions = 200 -- delay to use actions, like chest, lever, etc
timeBetweenExActions = 1000 -- delay to use items with use-with, like rope, shovel, machete, etc
 
Back
Top