SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 30/03/2020, 06:37 AM   #1
MarianImmortalGod
Big Clucker
 
Join Date: Mar 2018
Posts: 80
Reputation: 1
Default Timestamp detect and delete

Hello

I want to make a command that delete every account that didn't login in the past 30 days from his 'last log in' that i have.

Any idea how can i do this ?

P.S: I know that i need to check his 'last log in' but i don't know how to continue like 'last log in'+30 days = "DELETE DB ACCOUNT"
MarianImmortalGod is offline   Reply With Quote
Old 30/03/2020, 08:29 AM   #2
jasperschellekens
High-roller
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Holland
Posts: 1,014
Reputation: 92
Default Re: Timestamp detect and delete

What you could do here is use GetDate to get the day, month and year.
Code:
getdate(year, month, day);
Then you proceed on saving these stats for the player, preferably under onplayerconnect so it registers when the player has last connected.

Next thing you want to is create a timer that runs everyday to delete the actual account.
Now you could do something like this:
PHP Code:
Dbyear = ?
Dbmonth = ?
Dbday = ? // Let's imagine these 3 vars are used to load the last connected date for the player
getdate(yearmonthday);

if(
Dbmonth != month// Check if months are not equal.
{
    
//Since the day is the same and the month is not, it is highly likely the acc is 30 days old, This won't do the trick though, you'll have to setup additional checks to be a 100 percent sure, but this might help you on your way. 


__________________
Coming soon (6-1-2020):

Undead Wasteland Roleplay - The year is 1996. San Andreas is a wasteland ruled by the undead. the once so glorius landscape of San Andreas, is now a shattered decayed place that is only a vague memory of the world as we used to know it.
Official Live Beta Release Date: 1st of June, 2020
Discord - Website
jasperschellekens is offline   Reply With Quote
Old 30/03/2020, 08:41 AM   #3
MarianImmortalGod
Big Clucker
 
Join Date: Mar 2018
Posts: 80
Reputation: 1
Default Re: Timestamp detect and delete

Quote:
Originally Posted by jasperschellekens View Post
What you could do here is use GetDate to get the day, month and year.
Code:
getdate(year, month, day);
Then you proceed on saving these stats for the player, preferably under onplayerconnect so it registers when the player has last connected.

Next thing you want to is create a timer that runs everyday to delete the actual account.
Now you could do something like this:
PHP Code:
Dbyear = ?
Dbmonth = ?
Dbday = ? // Let's imagine these 3 vars are used to load the last connected date for the player
getdate(yearmonthday);

if(
Dbmonth != month// Check if months are not equal.
{
    
//Since the day is the same and the month is not, it is highly likely the acc is 30 days old, This won't do the trick though, you'll have to setup additional checks to be a 100 percent sure, but this might help you on your way. 


Yea u gived me the answear thanks a lot, about the different month it can be bugged by being in 29 last log and then in 1 like after 3 days or whatever month we are it will delete, cause different month, i wanted to know how to see if the account is older than 30 days without log
MarianImmortalGod is offline   Reply With Quote
Old 30/03/2020, 08:45 AM   #4
Adamoneoone
Huge Clucker
 
Join Date: Sep 2014
Posts: 468
Reputation: 35
Default Re: Timestamp detect and delete

Put simply add another column like LastLogin, in which you save a Timestamp whenevr a player logs in. Add a daily timer as jasper said which checks and compares timestamps, if the difference is hreater than 30 days run the delete qiery.
Adamoneoone is online now   Reply With Quote
Old 30/03/2020, 08:45 AM   #5
Pooh7
Huge Clucker
 
Pooh7's Avatar
 
Join Date: Aug 2010
Location: Serbia
Posts: 367
Reputation: 23
Default Re: Timestamp detect and delete

Code:
SELECT id FROM players WHERE last_login < NOW() - INTERVAL 30 DAY
Your last_login field should be of type DATETIME.
__________________
Pooh7 is offline   Reply With Quote
Old 30/03/2020, 08:49 AM   #6
Adamoneoone
Huge Clucker
 
Join Date: Sep 2014
Posts: 468
Reputation: 35
Default Re: Timestamp detect and delete

Quote:
Originally Posted by Pooh7 View Post
Code:
SELECT id FROM players WHERE last_login < NOW() - INTERVAL 30 DAY
Wonít this cause an issue if the server restarts? Letís say daily, it will never get run. Sorry if Iím wrong ^^.
Perhaps it will instead get run multiple times??
Adamoneoone is online now   Reply With Quote
Old 30/03/2020, 08:51 AM   #7
Pooh7
Huge Clucker
 
Pooh7's Avatar
 
Join Date: Aug 2010
Location: Serbia
Posts: 367
Reputation: 23
Default Re: Timestamp detect and delete

NOW() will return the current time and we're subtracting 30 days from that value. It has nothing to do with server restarts.
__________________
Pooh7 is offline   Reply With Quote
Old 30/03/2020, 08:54 AM   #8
MarianImmortalGod
Big Clucker
 
Join Date: Mar 2018
Posts: 80
Reputation: 1
Default Re: Timestamp detect and delete

Quote:
Originally Posted by Pooh7 View Post
Code:
SELECT id FROM players WHERE last_login < NOW() - INTERVAL 30 DAY
Your last_login field should be of type DATETIME.
Yea, this is what i wanted to have, thanks you verry much.

Thanks everyoen that posted.

PROBLEM SOLVED #Pooh7
MarianImmortalGod is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TimeStamp norton2 Scripting Help 7 30/08/2015 03:48 PM
Timestamp... Baltimore Scripting Help 30 21/01/2015 06:30 PM
timestamp SpartanacBH Scripting Help 4 30/07/2014 09:18 AM
Timestamp ScriptWriter Scripting Help 8 06/01/2013 07:15 PM
timestamp.. Exsite Scripting Help 7 22/10/2011 12:48 AM


All times are GMT. The time now is 08:53 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.