function onEquip(player, item, slot)
local cd = EXHAUSTTIME --in seconds
local storage = YOURSTORAGE
player:addStorageValue(storage, os.time() + cd)
if player:getStorageValue(storage) <= os.time() then
return true
else
return player:sendCancelMessage("You cannot equip this item yet") and false
end
end
local config = {
cooldown = 3000, -- milliseconds for more precision
storage = 99999 -- sample storage value
}
function onEquip(player, item, slot)
if player:getStorageValue(config.storage) <= os.mtime() then
player:setStorageValue(config.storage, os.mtime() + config.cooldown)
return true
end
player:sendCancelMessage("You cannot equip this item yet")
return false
end
I'm grateful for this answer, butyou should only be adding time if the 1st condition passes
otherwise you will never be able to equip the item because the value is always going to be greater than os.time()
you can also add this piece of code to force register abilities on items + execute script beforehand
if the script returns true it will handle registering the item as usual like you use function="onEquip" + a script
Update movement.cpp · Vulcanx/forgottenserver@1c78471
LUA:local config = { cooldown = 3000, -- milliseconds for more precision storage = 99999 -- sample storage value } function onEquip(player, item, slot) if player:getStorageValue(config.storage) <= os.mtime() then player:setStorageValue(config.storage, os.mtime() + config.cooldown) return true end player:sendCancelMessage("You cannot equip this item yet") return false end
uint32_t MoveEvent::fireEquip(Player* player, Item* item, slots_t slot, bool boolean)
{
if (m_scripted) {
return executeEquip(player, item, slot);
} else {
return equipFunction(this, player, item, slot, boolean);
}
}