Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if !defined REACTION_MAX_CHARS
- #define REACTION_MAX_CHARS 9
- #endif
- #if !defined REACTION_MIN_CHARS
- #define REACTION_MIN_CHARS 6
- #endif
- #if !defined REACTION_CHARS_LIST
- #define REACTION_CHARS_LIST "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
- #endif
- #define DEFAULT_REACTION_TIME_DELAY (3 * 60 * 1000)
- #define SetReactionTimeDelay(%0) reaction_arr[reaction_time_delay]=%0
- #define GetReactionTimeDelay() reaction_arr[reaction_time_delay]
- #define SetReactionTimer(%0) reaction_arr[reaction_timer]=%0
- #define GetReactionTimer() reaction_arr[reaction_timer]
- #define SetReactionWon(%0) reaction_arr[reaction_won]=%0
- #define IsReactionWon() reaction_arr[reaction_won]
- #define SetReactionString(%0) format(reaction_arr[reaction_string], sizeof(reaction_arr[reaction_string]), "%s", %0)
- #define GetReactionString() reaction_arr[reaction_string]
- #define React_GenerateRandomNumber(%0,%1) (%0 + random(%1-%0))
- enum reaction_information
- {
- reaction_time_delay,
- reaction_timer,
- bool: reaction_won,
- reaction_string[(REACTION_MAX_CHARS + 1)]
- }
- new reaction_arr[reaction_information];
- new char_list[] = REACTION_CHARS_LIST;
- forward OnNewReaction(reaction[]);
- forward OnReactionWon(playerid);
- stock ResetReactionTimer()
- {
- KillTimer(GetReactionTimer());
- SetReactionTimer(SetTimer("OnReactionCall", GetReactionTimeDelay(), true));
- return 1;
- }
- stock GenerateRandomString(to_generate[], len)
- {
- for(new i = 0; i < len; i++)
- {
- to_generate[i] = char_list[random(sizeof(char_list) - 1)];
- }
- return 1;
- }
- forward OnReactionCall();
- public OnReactionCall()
- {
- new react_string[REACTION_MAX_CHARS + 1];
- GenerateRandomString(react_string, React_GenerateRandomNumber(REACTION_MIN_CHARS, REACTION_MAX_CHARS));
- SetReactionString(react_string);
- SetReactionWon(false);
- CallRemoteFunction("OnNewReaction", "s", GetReactionString());
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- if(!IsReactionWon() && (strlen(text) <= REACTION_MAX_CHARS))
- {
- if(strcmp(GetReactionString(), text) == 0)
- {
- SetReactionWon(true);
- CallRemoteFunction("OnReactionWon", "d", playerid);
- }
- }
- CallRemoteFunction("React_OnPlayerText", "ds", playerid, text);
- return 1;
- }
- #if defined _ALS_OnPlayerText
- #undef OnPlayerText
- #else
- #define _ALS_OnPlayerText
- #endif
- #define OnPlayerText React_OnPlayerText
- forward React_OnPlayerText(playerid, text[]);
- public OnGameModeInit()
- {
- SetReactionTimeDelay(DEFAULT_REACTION_TIME_DELAY);
- ResetReactionTimer();
- CallRemoteFunction("React_OnGameModeInit", "");
- return 1;
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit React_OnGameModeInit
- forward React_OnGameModeInit();
- public OnGameModeExit()
- {
- KillTimer(GetReactionTimer());
- CallRemoteFunction("React_OnGameModeExit", "");
- return 1;
- }
- #if defined _ALS_OnGameModeExit
- #undef OnGameModeExit
- #else
- #define _ALS_OnGameModeExit
- #endif
- #define OnGameModeExit React_OnGameModeExit
- forward React_OnGameModeExit();
Advertisement
Add Comment
Please, Sign In to add comment