Guest User

Untitled

a guest
Dec 17th, 2010
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.83 KB | None | 0 0
  1. /*
  2.  *    Maths FILTERSCRIPT
  3.  *    This is a short minigame
  4.  *    Answer maths task for money
  5.  */
  6.  
  7.  
  8. #include <a_samp>
  9.  
  10. // Colours
  11. #define COLOR_GREEN         0x00CC00FF
  12. #define COLOR_RED           0xFF0000FF
  13. #define COLOR_YELLOW        0xFFFF00FF
  14. #define COLOR_ORANGE        0xEE9911FF
  15.  
  16. #define E_TIME              60        // Every how much seconds will new Maths game start
  17. #define E_MAX_NUMBER        50        // Whats the highest number for script to choose as random
  18. #define E_MIN_NUMBER        30        // Whats the smallest number for script to choose as random
  19. #define E_CASH              10000     // How much will the player get for solving the task successfully
  20.  
  21. #if E_MAX_NUMBER < E_MIN_NUMBER
  22.     #error "MAX_NUMBER shouldn't be less than MIN_NUMBER"
  23. #endif
  24.  
  25. enum E_SERVER_DATA
  26. {
  27.     bool: E_STARTED,
  28.     E_ANSWER,
  29.     E_START_TIME,
  30.     E_TIMER,
  31. }
  32. new gServerData[E_SERVER_DATA];
  33.  
  34. forward LoadGame();
  35.  
  36. public OnFilterScriptInit()
  37. {
  38.     print("Maths script is starting...");
  39.     print("Time between tests: " #E_TIME " seconds");
  40.     print("Min number: " #E_MIN_NUMBER "  Max number: " #E_MAX_NUMBER );
  41.     SendClientMessageToAll(COLOR_YELLOW,"Maths script has been loaded!");
  42.    
  43.     LoadGame();
  44.    
  45.     SetTimer("LoadGame",E_TIME*1000,true);
  46.     return 1;
  47. }
  48.  
  49. public OnFilterScriptExit()
  50. {
  51.     print("Maths script has been unloaded!");
  52.     return 1;
  53. }
  54.  
  55. public OnPlayerText(playerid, text[])
  56. {
  57.     if(gServerData[E_STARTED] && strval(text) == gServerData[E_ANSWER]) {
  58.         GivePlayerMoney(playerid,E_CASH);
  59.        
  60.         new msg[128],name[MAX_PLAYER_NAME];
  61.         GetPlayerName(playerid,name,sizeof(name));
  62.         format(msg,sizeof(msg),"%s solved a task successfully in %i seconds (Ans: %i)",name, GetTimerInSeconds(GetTickCount(),gServerData[E_START_TIME]), gServerData[E_ANSWER]);
  63.         SendClientMessageToAll(COLOR_YELLOW,msg);
  64.         print(msg);
  65.        
  66.         gServerData[E_STARTED] = false;
  67.         gServerData[E_ANSWER] = 0;
  68.         gServerData[E_START_TIME] = 0;
  69.         return 1;
  70.     }
  71.     return 1;
  72. }
  73.  
  74. public LoadGame()
  75. {
  76.     new E_NUM1 = random(E_MAX_NUMBER-E_MIN_NUMBER) + E_MIN_NUMBER,
  77.         E_NUM2 = random(E_MAX_NUMBER-E_MIN_NUMBER) + E_MIN_NUMBER,
  78.         E_NUM3 = random(E_MAX_NUMBER-E_MIN_NUMBER) + E_MIN_NUMBER,
  79.         E_NUM4 = random(E_MAX_NUMBER-E_MIN_NUMBER) + E_MIN_NUMBER;
  80.  
  81.     gServerData[E_STARTED] = true;
  82.     gServerData[E_ANSWER] = E_NUM1 + E_NUM2 - E_NUM3 + E_NUM4;
  83.     gServerData[E_START_TIME] = GetTickCount();
  84.    
  85.     new msg[128];
  86.     format(msg,sizeof(msg),"Solve for %i$ --> %i + %i - %i + %i = ?",E_CASH,E_NUM1,E_NUM2,E_NUM3,E_NUM4);
  87.     SendClientMessageToAll(COLOR_YELLOW,msg);
  88.     print(msg);
  89. }
  90.  
  91. GetTimerInSeconds(now, started)
  92. {
  93.    new secs, ms;
  94.    ms = now - started;
  95.    while(ms > 999) {
  96.        secs++;
  97.        ms = ms-1000;
  98.    }
  99.    return secs;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment