Lua os time () storage set for a time

Discussion in 'Support' started by ellvo, Jan 11, 2017.

  1. ellvo

    ellvo New Member

    Joined:
    Sep 23, 2016
    Messages:
    15
    Likes Received:
    2
    Best Answers:
    0
    As guys under corrected me,reposting

    I would need some help with os time() how it is working like or exactly,I need help with something like I need to set storage 9999,1 for 1 minute how to do that.

    if player:getStorageValue(56148) < 0 then
    player:setStorageValue(cid, 56148, os.time()+ 1 * 60) -- (it is default -1 need to make it 1 idk how)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You may enter this tp again in 1 minute.')
    end

    any ideas ?

    if player:getStorageValue(56148) == 1 then
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It is less then one minute you have entered the tp.')
    end
     
    Last edited: Jan 12, 2017
  2. Best Answer:
    Post #6 by Colandus, Jan 12, 2017
  3. Xeraphus

    Xeraphus Premium User Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,348
    Likes Received:
    925
    Best Answers:
    100
    don't just change thread title and edit your post, read the rules
    if you find a solution to your problem, let the thread be and post the solution incase someone else needs it.

    + if you want a thread deleted just report your own post and put delete in the reason
     
  4. Taurus

    Taurus Texass Premium User

    Joined:
    Jan 11, 2009
    Messages:
    517
    Likes Received:
    14
    Best Answers:
    1
    +1 for this

    Any mistake you can make, someone else can reproduce. You'll find I have two or three threads where I answer my own question.
     
  5. ellvo

    ellvo New Member

    Joined:
    Sep 23, 2016
    Messages:
    15
    Likes Received:
    2
    Best Answers:
    0
    bump
     
  6. andu

    andu Sold 649 scripts, 25 maps and 9 events!

    Joined:
    Aug 7, 2009
    Messages:
    807
    Likes Received:
    197
    Best Answers:
    6
    os.time() returns amount of seconds what have passed since 1970-01-01 00:00, becouse of big numbers here - 32bit systems will be not able to handle date after 2038 year

    If you want something like CD you can do it in multiple ways (from math side).

    Script logic order:
    1. Check if storage value is equal or greater then os.time() + 60
    2. If is greater or equal then teleport player and set his storage value to os.time() -- this will store time, when he last entered tp
    3. If is not greater or equal, then return "you cannot enter more then once per min"
     
  7. Colandus

    Colandus Support Team Support Team

    Joined:
    Jun 6, 2007
    Messages:
    2,424
    Likes Received:
    157
    Best Answers:
    18
    Best Answer
    Code (Text):
    1.  
    2. local lastTime = player:getStorageValue(56148)
    3.  
    4. local now = os.time()
    5.  
    6. -- If lastTime is -1 or 0 or any other low number, timePassed will be a long number rather than the exact time passed
    7. -- This means we can safely check if timePassed > x even if lastTime was 0 or -1
    8. local timePassed = now - lastTime
    9.  
    10. if timePassed >= 60 then
    11.         player:setStorageValue(56148, now)
    12.         player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You may enter this tp again in 1 minute.')
    13. else
    14.         player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It is less then one minute you have entered the tp.')
    15. end
    16.  

    Or we could do it your way and add time directly to storage (no big difference, but I prefer above way):
    Code (Text):
    1.  
    2. local lastTime = player:getStorageValue(56148)
    3.  
    4. local now = os.time()
    5.  
    6. -- If lastTime is -1 or 0 or any other low number, timePassed will be a long number rather than the exact time passed
    7. -- This means we can safely check if timePassed > x even if lastTime was 0 or -1
    8. local timePassed = now - lastTime
    9.  
    10. if timePassed >= 0 then
    11.         player:setStorageValue(56148, now + 60)
    12.         player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You may enter this tp again in 1 minute.')
    13. else
    14.         player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It is less then one minute you have entered the tp.')
    15. end
    16.  
     
    Last edited: Jan 12, 2017
  8. Xeraphus

    Xeraphus Premium User Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,348
    Likes Received:
    925
    Best Answers:
    100
    mm cid is not an argument for player methods anymore
     
  9. Colandus

    Colandus Support Team Support Team

    Joined:
    Jun 6, 2007
    Messages:
    2,424
    Likes Received:
    157
    Best Answers:
    18
    Yeah didn't check it, just copied his code
     
    Xeraphus likes this.

Share This Page

Loading...