Jump to content

[HELP] Consecutive login


#STZ

Recommended Posts

  • Discord Moderators

There's a few ways you can accomplish this. You could maintain a log of when the player has logged in and compare against that to see if they logged in 3 consecutive days. Another way is only keeping track of the last login and a counter of consecutive days thus far. If the user logs in and their last login wasn't the day before you reset the counter, otherwise if they did you increase it. Obviously if they logged in earlier on that same day you don't modify the counter.

Edited by Megadreams
Link to comment

@Hydrai only ask about the calculation method not store method

-----

@Megadreams

how can i create this function

isPlayerLoggedYesterday ( LastLogin , todayDate )

if LastLogin  = "2022-01-20" and todayDate "2022-01-21"

how can i know if that the day next or not ?

 

for example lastlogin may be 31 and today ma by day 1 its consecutive days

if LastLogin  = "2022-01-31" and todayDate "2022-02-1"

 

Link to comment

you can use getTimestamp() function to find previous day and current day this will return instant timestamp in seconds.

https://wiki.multitheftauto.com/wiki/GetTimestamp

Since 1 day is 86400 seconds, you will subtract this from the present
 

addCommandHandler("times", function()
   local time = getTimestamp()
   local beforeDay = time - 86400
   outputDebugString("before day:"..beforeDay)
   outputDebugString("now: "..time)
end)



this way you can access previous time and current time i'm not sure if this is what you want

Link to comment

You don't need to know the algorithm if you can make use of the getRealTime function. By giving it the seconds of current day you can fetch the datetime description of the next day by adding the amount of seconds that eoL|Shady has described. Then you can reconstruct the datestring from that time description. But I guess that eoL|Shady's answer might be enough to get you in the right direction.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...