Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Funkciju iškvietimo nurodytu laiku include
- Autorius "Bebras" 2013 - 2014 ©
- v0.1
- */
- /*
- native AddEvent(funcname[], bool:repeating, hour, minute=0, second=0);
- */
- #if !defined MAX_EVENTS
- #define MAX_EVENTS 15
- #endif
- #if !defined EVENTS_USE_YTIMERS
- #if defined _inc_y_timers
- #define EVENTS_USE_YTIMERS
- #endif
- #endif
- // Macro from Y_Less
- #if !defined strcpy
- #define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)
- #endif
- enum event_data {
- eFunctionName[32],
- eHour,
- eMinute,
- eSecond,
- eLastCall,
- bool:eActive,
- bool:eRepeat
- };
- new EventData[MAX_EVENTS][event_data];
- stock AddEvent(funcname[],bool:repeating,hour,minute=0,second=0)
- {
- for(new i = 0; i < sizeof(EventData); i++)
- {
- if(EventData[i][eActive]) continue;
- if(hour >= 24 || hour < 0) EventData[i][eHour] = 0;
- if(minute < 0 || minute > 59) minute = 0;
- if(second < 0 || second > 59) second = 0;
- EventData[i][eActive] = true;
- strcpy(EventData[i][eFunctionName],funcname,32);
- EventData[i][eHour] = hour;
- EventData[i][eMinute] = minute;
- EventData[i][eSecond] = second;
- EventData[i][eRepeat] = repeating;
- return 1;
- }
- return 0;
- }
- public OnGameModeInit()
- {
- #if !defined EVENTS_USE_YTIMERS
- #if defined _inc_timerfix
- SetTimer("EventTimeCheck", 1000, true);
- #else
- SetTimer("EventTimeCheck", 600, true);
- #endif
- #endif
- #if defined Event_OnGameModeInit
- Event_OnGameModeInit();
- #endif
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit Event_OnGameModeInit
- #if defined Event_OnGameModeInit
- forward Event_OnGameModeInit();
- #endif
- #if defined EVENTS_USE_YTIMERS
- task EventTimeCheckYTimers[1000]()
- EventTimeCheck();
- #endif
- forward EventTimeCheck();
- public EventTimeCheck()
- {
- new hour,minute,second,stamp = gettime();
- gettime(hour,minute,second);
- for(new i = 0; i < sizeof(EventData); i++)
- {
- if(!EventData[i][eActive]) break;
- if(hour == EventData[i][eHour] && minute == EventData[i][eMinute]
- && second >= EventData[i][eSecond] && second > EventData[i][eLastCall])
- {
- CallLocalFunction(EventData[i][eFunctionName],"","");
- EventData[i][eLastCall] = stamp;
- printf("Calling %s",EventData[i][eFunctionName]);
- if(!EventData[i][eRepeat])
- {
- EventData[i][eActive] = false;
- strdel(EventData[i][eFunctionName],0,32);
- }
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment