Guest User

dreactions 1.0.0

a guest
May 2nd, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.13 KB | None | 0 0
  1. #if !defined REACTION_MAX_CHARS
  2.     #define REACTION_MAX_CHARS              9
  3. #endif
  4.  
  5. #if !defined REACTION_MIN_CHARS
  6.     #define REACTION_MIN_CHARS              6
  7. #endif
  8.  
  9. #if !defined REACTION_CHARS_LIST
  10.     #define REACTION_CHARS_LIST             "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  11. #endif
  12.  
  13. #define DEFAULT_REACTION_TIME_DELAY         (3 * 60 * 1000)
  14.  
  15. #define SetReactionTimeDelay(%0)            reaction_arr[reaction_time_delay]=%0
  16. #define GetReactionTimeDelay()              reaction_arr[reaction_time_delay]
  17.  
  18. #define SetReactionTimer(%0)                reaction_arr[reaction_timer]=%0
  19. #define GetReactionTimer()                  reaction_arr[reaction_timer]
  20.  
  21. #define SetReactionWon(%0)                  reaction_arr[reaction_won]=%0
  22. #define IsReactionWon()                     reaction_arr[reaction_won]
  23.  
  24. #define SetReactionString(%0)               format(reaction_arr[reaction_string], sizeof(reaction_arr[reaction_string]), "%s", %0)
  25. #define GetReactionString()                 reaction_arr[reaction_string]
  26.  
  27. #define React_GenerateRandomNumber(%0,%1)   (%0 + random(%1-%0))
  28.  
  29. enum reaction_information
  30. {
  31.     reaction_time_delay,
  32.     reaction_timer,
  33.     bool: reaction_won,
  34.     reaction_string[(REACTION_MAX_CHARS + 1)]
  35. }
  36. new reaction_arr[reaction_information];
  37. new char_list[] = REACTION_CHARS_LIST;
  38.  
  39. forward OnNewReaction(reaction[]);
  40. forward OnReactionWon(playerid);
  41.  
  42. stock ResetReactionTimer()
  43. {
  44.     KillTimer(GetReactionTimer());
  45.     SetReactionTimer(SetTimer("OnReactionCall", GetReactionTimeDelay(), true));
  46.     return 1;
  47. }
  48.  
  49. stock GenerateRandomString(to_generate[], len)
  50. {
  51.     for(new i = 0; i < len; i++)
  52.     {
  53.         to_generate[i] = char_list[random(sizeof(char_list) - 1)];
  54.     }
  55.     return 1;
  56. }
  57.  
  58. forward OnReactionCall();
  59. public OnReactionCall()
  60. {
  61.     new react_string[REACTION_MAX_CHARS + 1];
  62.    
  63.     GenerateRandomString(react_string, React_GenerateRandomNumber(REACTION_MIN_CHARS, REACTION_MAX_CHARS));
  64.     SetReactionString(react_string);
  65.    
  66.     SetReactionWon(false);
  67.    
  68.     CallRemoteFunction("OnNewReaction", "s", GetReactionString());
  69.     return 1;
  70. }
  71.  
  72. public OnPlayerText(playerid, text[])
  73. {
  74.     if(!IsReactionWon() && (strlen(text) <= REACTION_MAX_CHARS))
  75.     {
  76.         if(strcmp(GetReactionString(), text) == 0)
  77.         {
  78.             SetReactionWon(true);
  79.             CallRemoteFunction("OnReactionWon", "d", playerid);
  80.         }
  81.     }
  82.     CallRemoteFunction("React_OnPlayerText", "ds", playerid, text);
  83.     return 1;
  84. }
  85.  
  86. #if defined _ALS_OnPlayerText
  87.     #undef OnPlayerText
  88. #else
  89.     #define _ALS_OnPlayerText
  90. #endif
  91. #define OnPlayerText React_OnPlayerText
  92. forward React_OnPlayerText(playerid, text[]);
  93.  
  94.  
  95. public OnGameModeInit()
  96. {
  97.     SetReactionTimeDelay(DEFAULT_REACTION_TIME_DELAY);
  98.     ResetReactionTimer();
  99.     CallRemoteFunction("React_OnGameModeInit", "");
  100.     return 1;
  101. }
  102.  
  103. #if defined _ALS_OnGameModeInit
  104.     #undef OnGameModeInit
  105. #else
  106.     #define _ALS_OnGameModeInit
  107. #endif
  108. #define OnGameModeInit React_OnGameModeInit
  109. forward React_OnGameModeInit();
  110.  
  111. public OnGameModeExit()
  112. {
  113.     KillTimer(GetReactionTimer());
  114.     CallRemoteFunction("React_OnGameModeExit", "");
  115.     return 1;
  116. }
  117.  
  118. #if defined _ALS_OnGameModeExit
  119.     #undef OnGameModeExit
  120. #else
  121.     #define _ALS_OnGameModeExit
  122. #endif
  123. #define OnGameModeExit React_OnGameModeExit
  124. forward React_OnGameModeExit();
Advertisement
Add Comment
Please, Sign In to add comment