11.11.2018, 05:24
How can i check if a day has passed ?
Check https://sampwiki.blast.hk/wiki/Gettime
And https://sampwiki.blast.hk/wiki/Getdate Saving them to a variable and checking days should do it. |
forward NewDay();
public NewDay()
{
SendClientMessageToAll(-1, "Rise and Shine, It's a new day!");
return 1;
}
public OnGameModeInit()
{
SetWorldTime(0);
SetTimer("NewDay", 1440000, true);
return 1;
}
#define HOURS_TO_SECONDS(%0) (%0 * 3600) // hour to seconds convertor
new serverTimestamp;
new serverUpdateTimer;
public OnGameModeInit() {
serverTimestamp = gettime(); // when your server starts, store the timestamp into your global variable
serverUpdateTimer = SetTimer("OnServerUpdate", 1000, true); // a timer which will iterate every 1 second
}
forward OnServerUpdate();
public OnServerUpdate() {
new currentTimestamp = gettime(); // get the current timestamp
if (serverTimestamp - currentTimestamp >= HOURS_TO_SECONDS(1)) { // 1 hour has passed in your server
// do your code here
// reset our variable so we keep track for next hour pass
currentTimestamp = serverTimestamp;
}
}