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

Lua Stamina Refil.

kleitonalan

New Member
Joined
Mar 21, 2013
Messages
289
Reaction score
3
with time to use it again after 24 hours

stamina.lua

function onUse(cid, item, fromPosition, itemEx, toPosition)
local cfg = {}
cfg.refuel = 42 * 60 * 1000
if(getPlayerStamina(cid) >= cfg.refuel) then
doPlayerSendCancel(cid, "Your stamina is already full.")
else
doPlayerSetStamina(cid, cfg.refuel)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
doRemoveItem(item.uid)
end
return true
end
 
I'm not sure what the question is.. Are you asking how to add a 24-hour delay between usage?
 
Try this:

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local delaytime = 86400
local cfg = {}
cfg.refuel = 42 * 60 * 1000
if getPlayerStorageValue(cid, 63344) >= os.time() then
doPlayerPopupFYI(cid, "You may only use this once a day!")
elseif(getPlayerStamina(cid) >= cfg.refuel) then
doPlayerSendCancel(cid, "Your stamina is already full.")
else
setPlayerStorageValue(cid, 63344, os.time()+delaytime)
doPlayerSetStamina(cid, cfg.refuel)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
doRemoveItem(item.uid)
end
return true
end
 
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local timeToUse = 86400
local lastTime = 0
local osTime = os.time()
local cfg = {}
cfg.refuel = 42 * 60 * 1000
if(getPlayerStamina(cid) >= cfg.refuel) then
doPlayerSendCancel(cid, "Your stamina is already full.")
elseif(lastTime <= osTime) then
doPlayerSendCancel(cid, "You can use this every 24h!")
else
doPlayerSetStamina(cid, cfg.refuel)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
doRemoveItem(item.uid)
lastTime = osTime + timeToUse
end
return true
end

edit: fuck didn't see you already posted one haha

edit 2: first I did it with a script I had, now with the one he posted
 
Last edited:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local timeToUse = 86400
local lastTime = 0
local osTime = os.time()
local cfg = {}
cfg.refuel = 42 * 60 * 1000
if(getPlayerStamina(cid) >= cfg.refuel) then
doPlayerSendCancel(cid, "Your stamina is already full.")
elseif(lastTime <= osTime) then
doPlayerSendCancel(cid, "You can use this every 24h!")
else
doPlayerSetStamina(cid, cfg.refuel)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
doRemoveItem(item.uid)
lastTime = osTime + timeToUse
end
return true
end

edit: fuck didn't see you already posted one haha

edit 2: first I did it with a script I had, now with the one he posted

Its better to use storage values insted of a local variable.
 
Back
Top