• 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 How change to need wait 30 days to use stamina pot

danbsten

New Member
Joined
Aug 3, 2015
Messages
53
Reaction score
1
How change to need wait 30 days to use stamina pot

Code:
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.")
   --elseif(not isPremium(cid)) then
   --   doPlayerSendCancel(cid, "You must have a premium account.")
   else
     doPlayerSetStamina(cid, cfg.refuel)
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
     doRemoveItem(item.uid)
   end
   return true
end
 
currently you have it set for 42 hours.. So either count how many hours in 30 days and put that in, or make it 24 and count days..
Code:
720 * 60 * 1000
30 * 24 * 60 * 1000
 
You can use storage value and os.time() to hold the timestamp you last used it.
Code:
doCreatureSetStorage(cid, storagevaluehere, os.time())
Then just compare the current time to the stored time to determine if it is on cooldown.
Code:
if(os.time() < getCreatureStorage(cid, storagevaluehere) + (30*24*60*60)) then
     -- cooldown msg?
     return true
end
 
You can use storage value and os.time() to hold the timestamp you last used it.
Code:
doCreatureSetStorage(cid, storagevaluehere, os.time())
Then just compare the current time to the stored time to determine if it is on cooldown.
Code:
if(os.time() < getCreatureStorage(cid, storagevaluehere) + (30*24*60*60)) then
     -- cooldown msg?
     return true
end

Ty

I made right?

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local exaustedstamina = 3024774
   local cfg = {}
   cfg.refuel = 42 * 60 * 1000
   if(os.time() < getCreatureStorage(cid, exaustedstamina) + (30*24*60*60)) then
      doPlayerSendCancel(cid, "You can only use it once every 30 days!")
      return true
   end
   if(getPlayerStamina(cid) >= cfg.refuel) then
     doPlayerSendCancel(cid, "Your stamina is already full.")
   --elseif(not isPremium(cid)) then
   --   doPlayerSendCancel(cid, "You must have a premium account.")
   else
     doPlayerSetStamina(cid, cfg.refuel)
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
     doRemoveItem(item.uid)
     doCreatureSetStorage(cid, exaustedstamina, os.time())
   end
   return true
end
 
Ty

I made right?

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local exaustedstamina = 3024774
   local cfg = {}
   cfg.refuel = 42 * 60 * 1000
   if(os.time() < getCreatureStorage(cid, exaustedstamina) + (30*24*60*60)) then
      doPlayerSendCancel(cid, "You can only use it once every 30 days!")
      return true
   end
   if(getPlayerStamina(cid) >= cfg.refuel) then
     doPlayerSendCancel(cid, "Your stamina is already full.")
   --elseif(not isPremium(cid)) then
   --   doPlayerSendCancel(cid, "You must have a premium account.")
   else
     doPlayerSetStamina(cid, cfg.refuel)
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
     doRemoveItem(item.uid)
     doCreatureSetStorage(cid, exaustedstamina, os.time())
   end
   return true
end
You'll most likely get an error using a storage value that long.. "3024774"
but otherwise it appears to be fine.
 
@Xikini
Looks like hes using the older tfs which means storage is saved as a string.
Code:
doCreatureSetStorage(cid, "randomstoragename", "huehuehue")
 
@Xikini
Looks like hes using the older tfs which means storage is saved as a string.
Code:
doCreatureSetStorage(cid, "randomstoragename", "huehuehue")

I dont understand you


Guys how i could make msg error
Code:
doPlayerSendCancel(cid, "You can only use it once every 30 days!")

To something like:
Left 25 days to u use it again! Wait!
 
I dont understand you


Guys how i could make msg error
Code:
doPlayerSendCancel(cid, "You can only use it once every 30 days!")

To something like:
Left 25 days to u use it again! Wait!

How to use a variable to show how many days left to use again!?
 
How to use a variable to show how many days left to use again!?
try this
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local exhaustedstamina = 3024774
   local cfg = {}
   cfg.refuel = 42 * 60 * 1000
   if(os.time() < getCreatureStorage(cid, exhaustedstamina) then
     doPlayerSendCancel(cid, "You can only use it once every 30 days! You will be able to use this item again on: " .. os.date("%c", getPlayerStorageValue(cid, exhaustedstamina)) .. ".")
     return true
   end
   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)
     doCreatureSetStorage(cid, exhaustedstamina, os.time() + (30*24*60*60))
   end
   return true
end
 
try this
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local exhaustedstamina = 3024774
   local cfg = {}
   cfg.refuel = 42 * 60 * 1000
   if(os.time() < getCreatureStorage(cid, exhaustedstamina) then
     doPlayerSendCancel(cid, "You can only use it once every 30 days! You will be able to use this item again on: " .. os.date("%c", getPlayerStorageValue(cid, exhaustedstamina)) .. ".")
     return true
   end
   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)
     doCreatureSetStorage(cid, exhaustedstamina, os.time() + (30*24*60*60))
   end
   return true
end

Ty, but its not possible show how many days left?
Date can to confuse my players because i will have BRs and NO-BRS and in brazil date = day/mouth/year, ou is mouth/day/year

Could you change it for me?
 
Ty, but its not possible show how many days left?
Date can to confuse my players because i will have BRs and NO-BRS and in brazil date = day/mouth/year, ou is mouth/day/year

Could you change it for me?
Code:
%a abbreviated weekday name (e.g., Wed)
%A full weekday name (e.g., Wednesday)
%b abbreviated month name (e.g., Sep)
%B full month name (e.g., September)
%c date and time (e.g., 09/16/98 23:48:10)
%d day of the month (16) [01-31]
%H hour, using a 24-hour clock (23) [00-23]
%I hour, using a 12-hour clock (11) [01-12]
%M minute (48) [00-59]
%m month (09) [01-12]
%p either "am" or "pm" (pm)
%S second (10) [00-61]
%w weekday (3) [0-6 = Sunday-Saturday]
%x date (e.g., 09/16/98)
%X time (e.g., 23:48:10)
%Y full year (1998)
%y two-digit year (98) [00-99]
%% the character `%´
http://www.lua.org/pil/22.1.html
 
Last edited:
Code:
%a abbreviated weekday name (e.g., Wed)
%A full weekday name (e.g., Wednesday)
%b abbreviated month name (e.g., Sep)
%B full month name (e.g., September)
%c date and time (e.g., 09/16/98 23:48:10)
%d day of the month (16) [01-31]
%H hour, using a 24-hour clock (23) [00-23]
%I hour, using a 12-hour clock (11) [01-12]
%M minute (48) [00-59]
%m month (09) [01-12]
%p either "am" or "pm" (pm)
%S second (10) [00-61]
%w weekday (3) [0-6 = Sunday-Saturday]
%x date (e.g., 09/16/98)
%X time (e.g., 23:48:10)
%Y full year (1998)
%y two-digit year (98) [00-99]
%% the character `%´

Tyyyyyy so mcuh!
http://www.lua.org/pil/22.1.html


Ty so much!!!
 
Back
Top Bottom