Advertisement
CheezPuff

[Free] JB Challenges First [New Version]

Dec 21st, 2024 (edited)
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.68 KB | None | 0 0
  1. /* 21/12/2024 Lastest Version of my FirstWrite
  2.     v1.1 - Dynamic CT Requirement Calculation
  3.     v1.2 - Improved Ratio Function | Clear HUD Messages on Stop
  4.     v1.3 - Consistent Chat Colors | Game State Management
  5. */
  6.  
  7. #include <amxmodx>
  8. #include <amxmisc>
  9. #include <cstrike>
  10. #include <hamsandwich>
  11. #include <fun>
  12.  
  13. #define ADMIN_FLAG ADMIN_KICK
  14. #define MAX_PLAYERS 32
  15. #define CHALLENGE_TIMEOUT 30.0  // Changed to 30 seconds as per requirements
  16. #define CHECK_INTERVAL 10.0
  17.  
  18. new bool:g_GameActive = false;
  19. new g_CountdownTime;
  20. new g_Answer[32];  // Changed to string to handle both numbers and text
  21. new bool:g_WinnerFound = false;
  22. new g_GameType;
  23. new g_NoResponseCount = 0;
  24.  
  25. enum _:GameTypes {
  26.     GAME_FIRSTWRITE = 1,
  27.     GAME_GUESS,
  28.     GAME_MATH
  29. }
  30.  
  31. public plugin_init() {
  32.     register_plugin("JB Challenges First", "1.0", "CheezPuff (Ariel)");
  33.    
  34.     // Register commands
  35.     register_concmd("say /first", "CmdStartGame", ADMIN_FLAG); // פקודה להפעיל בצאט
  36.     register_concmd("say /random", "CmdStartGame", ADMIN_FLAG); // פקודה להפעיל בצאט
  37.     register_concmd("say /fw", "CmdStartGame", ADMIN_FLAG); // פקודה להפעיל בצאט
  38.    
  39.     register_clcmd("say", "HandleSay");
  40.     register_clcmd("say_team", "HandleSay");
  41.    
  42.     set_task(CHECK_INTERVAL, "CheckTerroristCount", .flags="b");
  43. }
  44.  
  45. public CheckTerroristCount(taskid) {
  46.     if (g_GameActive)
  47.         return;
  48.        
  49.     new tCount = get_team_count(CS_TEAM_T);
  50.    
  51.     if (tCount >= 9) {
  52.         StartGameCountdown();
  53.     }
  54. }
  55.  
  56. public CmdStartGame(id, level, cid) {
  57.     if (!cmd_access(id, level, cid, 1))
  58.         return PLUGIN_HANDLED;
  59.    
  60.     if (g_GameActive) {
  61.         client_print(id, print_chat, "[JB] A challenge is already in progress!");
  62.         return PLUGIN_HANDLED;
  63.     }
  64.    
  65.     new tCount = get_team_count(CS_TEAM_T);
  66.     if (tCount < 2) {
  67.         client_print(id, print_chat, "[JB] Need at least 2 terrorists to start a challenge!");
  68.         return PLUGIN_HANDLED;
  69.     }
  70.    
  71.     StartGameCountdown();
  72.    
  73.     return PLUGIN_HANDLED;
  74. }
  75.  
  76. stock get_team_count(CsTeams:team) {
  77.     new players[MAX_PLAYERS], num;
  78.     get_players(players, num, "ae", team == CS_TEAM_T ? "TERRORIST" : "CT");
  79.     return num;
  80. }
  81.  
  82. public StartGameCountdown() {
  83.     g_GameActive = true;
  84.     g_WinnerFound = false;
  85.     g_CountdownTime = 5;
  86.    
  87.     g_GameType = random_num(GAME_FIRSTWRITE, GAME_MATH);
  88.    
  89.     new gameTypeName[32];
  90.     GetGameTypeName(g_GameType, gameTypeName, charsmax(gameTypeName));
  91.    
  92.     // Show countdown in HUD
  93.     set_hudmessage(255, 255, 0, -1.0, 0.35, 0, 6.0, 12.0, 0.1, 0.1);
  94.     show_hudmessage(0, "%s will start in 5 seconds", gameTypeName);
  95.    
  96.     set_task(1.0, "CountdownTimer", .flags="a", .repeat=5);
  97. }
  98.  
  99. public CountdownTimer() {
  100.     g_CountdownTime--;
  101.    
  102.     if (g_CountdownTime > 0) {
  103.         // Show countdown numbers in HUD
  104.         set_hudmessage(255, 0, 0, -1.0, 0.35, 0, 1.0, 1.0, 0.1, 0.1);
  105.         show_hudmessage(0, "%d", g_CountdownTime);
  106.         emit_sound(0, CHAN_VOICE, "fvox/doop.wav", 1.0, ATTN_NORM, 0, PITCH_NORM);
  107.     } else {
  108.         StartSelectedGame();
  109.         remove_task();
  110.     }
  111. }
  112.  
  113. public StartSelectedGame() {
  114.     switch(g_GameType) {
  115.         case GAME_FIRSTWRITE: {
  116.             new chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  117.             new output[6];
  118.             for (new i = 0; i < 5; i++) {
  119.                 output[i] = chars[random_num(0, strlen(chars) - 1)];
  120.             }
  121.             output[5] = 0;
  122.             copy(g_Answer, charsmax(g_Answer), output);
  123.            
  124.             set_hudmessage(255, 255, 0, -1.0, 0.35, 0, CHALLENGE_TIMEOUT, 1.0);
  125.             show_hudmessage(0, "First to write: %s", output);
  126.         }
  127.        
  128.         case GAME_GUESS: {
  129.             new num = random_num(1, 150);
  130.             num_to_str(num, g_Answer, charsmax(g_Answer));
  131.            
  132.             set_hudmessage(255, 255, 0, -1.0, 0.35, 0, CHALLENGE_TIMEOUT, 1.0);
  133.             show_hudmessage(0, "Guess the number between 1 and 150!");
  134.         }
  135.        
  136.         case GAME_MATH: {
  137.             new num1 = random_num(1, 50);
  138.             new num2 = random_num(1, 50);
  139.             new operation = random_num(1, 2);
  140.             new result;
  141.            
  142.             if (operation == 1) {
  143.                 result = num1 + num2;
  144.                 num_to_str(result, g_Answer, charsmax(g_Answer));
  145.                
  146.                 set_hudmessage(255, 255, 0, -1.0, 0.35, 0, CHALLENGE_TIMEOUT, 1.0);
  147.                 show_hudmessage(0, "Math Question: %d + %d = ?", num1, num2);
  148.             } else {
  149.                 result = num1 - num2;
  150.                 num_to_str(result, g_Answer, charsmax(g_Answer));
  151.                
  152.                 set_hudmessage(255, 255, 0, -1.0, 0.35, 0, CHALLENGE_TIMEOUT, 1.0);
  153.                 show_hudmessage(0, "Math Question: %d - %d = ?", num1, num2);
  154.             }
  155.         }
  156.     }
  157.    
  158.     set_task(CHALLENGE_TIMEOUT, "EndGameNoWinner");
  159. }
  160.  
  161. public HandleSay(id) {
  162.     if (!g_GameActive || g_WinnerFound || !is_user_connected(id))
  163.         return PLUGIN_CONTINUE;
  164.    
  165.     if (cs_get_user_team(id) != CS_TEAM_T) {
  166.         client_print(id, print_chat, "[JB] Only terrorists can participate in challenges!");
  167.         return PLUGIN_CONTINUE;
  168.     }
  169.    
  170.     new said[32];
  171.     read_args(said, charsmax(said));
  172.     remove_quotes(said);
  173.     trim(said);
  174.    
  175.     if (strlen(said) < 1)
  176.         return PLUGIN_CONTINUE;
  177.    
  178.     switch(g_GameType) {
  179.         case GAME_FIRSTWRITE: {
  180.             if (equal(said, g_Answer, strlen(g_Answer))) {
  181.                 DeclareWinner(id, "First Write");
  182.             }
  183.         }
  184.        
  185.         case GAME_GUESS: {
  186.             new guess = str_to_num(said);
  187.             new answer = str_to_num(g_Answer);
  188.            
  189.             if (guess == answer) {
  190.                 DeclareWinner(id, "Number Guess");
  191.             } else if (guess > 0 && guess <= 150) {
  192.                 client_print(id, print_chat, "[JB] %s! The number is %s",
  193.                     guess < answer ? "Higher" : "Lower",
  194.                     abs(guess - answer) <= 10 ? "very close" : "far");
  195.             }
  196.         }
  197.        
  198.         case GAME_MATH: {
  199.             if (str_to_num(said) == str_to_num(g_Answer)) {
  200.                 DeclareWinner(id, "Math");
  201.             }
  202.         }
  203.     }
  204.    
  205.     return PLUGIN_CONTINUE;
  206. }
  207.  
  208. public DeclareWinner(id, const gameType[]) {
  209.     if (g_WinnerFound || !is_user_connected(id))
  210.         return;
  211.    
  212.     g_WinnerFound = true;
  213.     g_GameActive = false;
  214.     g_NoResponseCount = 0;
  215.    
  216.     // Move to CT team and respawn
  217.     cs_set_user_team(id, CS_TEAM_CT);
  218.     ExecuteHamB(Ham_CS_RoundRespawn, id);
  219.    
  220.     new name[32];
  221.     get_user_name(id, name, charsmax(name));
  222.     client_print(0, print_chat, "[JB] %s has won the %s challenge and moved to CT!", name, gameType);
  223.    
  224.     remove_task();
  225.     set_task(5.0, "CheckTerroristCount");
  226. }
  227.  
  228. public EndGameNoWinner() {
  229.     if (!g_GameActive)
  230.         return;
  231.    
  232.     g_GameActive = false;
  233.     g_NoResponseCount++;
  234.    
  235.     client_print(0, print_chat, "[JB] Time's up! No one won the challenge.");
  236.    
  237.     if (g_NoResponseCount >= 2) {
  238.         client_print(0, print_chat, "[JB] Starting a new challenge automatically...");
  239.         g_NoResponseCount = 0;
  240.         set_task(3.0, "StartGameCountdown");
  241.     }
  242.    
  243.     set_task(5.0, "CheckTerroristCount");
  244. }
  245.  
  246. GetGameTypeName(type, output[], len) {
  247.     switch(type) {
  248.         case GAME_FIRSTWRITE: copy(output, len, "First Write Challenge");
  249.         case GAME_GUESS: copy(output, len, "Number Guess Challenge");
  250.         case GAME_MATH: copy(output, len, "Math Challenge");
  251.         default: copy(output, len, "Unknown Challenge");
  252.     }
  253. }
Tags: #cs1.6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement