Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Timeupdate Include/Timer (timeupdater.inc)
- * Now its possible to just use one timer for all your player functioning and updating using OnPlayerTimeUpdate!
- * Now its possible to just use one timer for all your global functioning and updaing using OnTimeUpdate, ALSO!
- Author: (creator)
- * Gammix
- (c) Copyright 2015
- * This file is provided as is (no warranties).
- */
- /*
- CALLBACKS:
- public OnPlayerTimeUpdate(playerid, hours, minutes, seconds)
- public OnTimeUpdate(hours, minutes, seconds)
- */
- static gPlayerSecondsTimer[MAX_PLAYERS];
- static gGlobalSecondsTimer;
- static gTimeCount[3];
- //internal function
- stock static TIMER_GetPlayerConnectedTime(playerid, &hours, &minutes, &seconds)
- {
- new connected_time = NetStats_GetConnectedTime(playerid);
- seconds = (connected_time / 1000) % 60;
- minutes = (connected_time / (1000 * 60)) % 60;
- hours = (connected_time / (1000 * 60 * 60));
- return true;
- }
- //Note: if you use this in a filterscript, please define "FILTERSCRIPT" in your script
- #if defined FILTERSCRIPT// if used in a filterscript
- public OnFilterScriptInit()
- {
- gGlobalSecondsTimer = SetTimerEx("OnTimeUpdate", 1 * 1000, "iii", false, gTimeCount[0], gTimeCount[1], gTimeCount[2]);
- return CallLocalFunction("TIMER_OnFilterScriptInit", "");
- }
- #if defined _ALS_OnFilterScriptInit
- #undef OnFilterScriptInit
- #else
- #define _ALS_OnFilterScriptInit
- #endif
- #define OnFilterScriptInit TIMER_OnFilterScriptInit
- forward TIMER_OnFilterScriptInit();
- public OnFilterScriptExit()
- {
- KillTimer(gGlobalSecondsTimer);
- return CallLocalFunction("TIMER_OnFilterScriptExit", "");
- }
- #if defined _ALS_OnFilterScriptExit
- #undef OnFilterScriptExit
- #else
- #define _ALS_OnFilterScriptExit
- #endif
- #define OnFilterScriptExit TIMER_OnFilterScriptExit
- forward TIMER_OnFilterScriptExit();
- #else// if used in a gamemode
- public OnGameModeInit()
- {
- gGlobalSecondsTimer = SetTimerEx("OnTimeUpdate", 1 * 1000, false, "iii", gTimeCount[0], gTimeCount[1], gTimeCount[2]);
- return CallLocalFunction("TIMER_OnGameModeInit", "");
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit TIMER_OnGameModeInit
- forward TIMER_OnGameModeInit();
- public OnGameModeExit()
- {
- KillTimer(gGlobalSecondsTimer);
- return CallLocalFunction("TIMER_OnGameModeExit", "");
- }
- #if defined _ALS_OnGameModeExit
- #undef OnGameModeExit
- #else
- #define _ALS_OnGameModeExit
- #endif
- #define OnGameModeExit TIMER_OnGameModeExit
- forward TIMER_OnGameModeExit();
- #endif
- public OnPlayerConnect(playerid)
- {
- static hours, minutes, seconds;
- TIMER_GetPlayerConnectedTime(playerid, hours, minutes, seconds);
- gPlayerSecondsTimer[playerid] = SetTimerEx("OnPlayerTimeUpdate", 1* 1000, false, "iiii", playerid, hours, minutes, seconds);
- return CallLocalFunction("TIMER_OnPlayerConnect", "i", playerid);
- }
- #if defined _ALS_OnPlayerConnect
- #undef OnPlayerConnect
- #else
- #define _ALS_OnPlayerConnect
- #endif
- #define OnPlayerConnect TIMER_OnPlayerConnect
- forward TIMER_OnPlayerConnect(playerid);
- public OnPlayerDisconnect(playerid, reason)
- {
- KillTimer(gPlayerSecondsTimer[playerid]);
- return CallLocalFunction("TIMER_OnPlayerDisconnect", "ii", playerid, reason);
- }
- #if defined _ALS_OnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define _ALS_OnPlayerDisconnect
- #endif
- #define OnPlayerDisconnect TIMER_OnPlayerDisconnect
- forward TIMER_OnPlayerDisconnect(playerid, reason);
- forward OnPlayerTimeUpdate(playerid, hours, minutes, seconds);
- public OnPlayerTimeUpdate(playerid, hours, minutes, seconds)
- {
- hours = 0, minutes = 0, seconds = 0;
- TIMER_GetPlayerConnectedTime(playerid, hours, minutes, seconds);
- gPlayerSecondsTimer[playerid] = SetTimerEx("OnPlayerTimeUpdate", 1* 1000, false, "iiii", playerid, hours, minutes, seconds);
- return CallLocalFunction("TIMER_OnPlayerTimeUpdate", "iiii", playerid, hours, minutes, seconds);
- }
- #if defined _ALS_OnPlayerTimeUpdate
- #undef OnPlayerTimeUpdate
- #else
- #define _ALS_OnPlayerTimeUpdate
- #endif
- #define OnPlayerTimeUpdate TIMER_OnPlayerTimeUpdate
- forward TIMER_OnPlayerTimeUpdate(playerid, hours, minutes, seconds);
- forward OnTimeUpdate(hours, minutes, seconds);
- public OnTimeUpdate(hours, minutes, seconds)
- {
- gTimeCount[2] += 1;
- if(gTimeCount[2] >= 60)
- {
- gTimeCount[2] = 0;
- gTimeCount[1] += 1;
- if(gTimeCount[1] >= 60)
- {
- gTimeCount[1] = 0;
- gTimeCount[0] += 1;
- }
- }
- hours = 0, minutes = 0, seconds = 0;
- gGlobalSecondsTimer = SetTimerEx("OnTimeUpdate", 1* 1000, false, "iii", gTimeCount[0], gTimeCount[1], gTimeCount[2]);
- return CallLocalFunction("TIMER_OnTimeUpdate", "iii", hours, minutes, seconds);
- }
- #if defined _ALS_OnTimeUpdate
- #undef OnTimeUpdate
- #else
- #define _ALS_OnTimeUpdate
- #endif
- #define OnTimeUpdate TIMER_OnTimeUpdate
- forward TIMER_OnTimeUpdate(hours, minutes, seconds);
Advertisement
Add Comment
Please, Sign In to add comment