Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 21/12/2024 Lastest Version of my FirstWrite
- v1.1 - Dynamic CT Requirement Calculation
- v1.2 - Improved Ratio Function | Clear HUD Messages on Stop
- v1.3 - Consistent Chat Colors | Game State Management
- */
- #include <amxmodx>
- #include <amxmisc>
- #include <cstrike>
- #include <hamsandwich>
- #include <fun>
- #define ADMIN_FLAG ADMIN_KICK
- #define MAX_PLAYERS 32
- #define CHALLENGE_TIMEOUT 30.0 // Changed to 30 seconds as per requirements
- #define CHECK_INTERVAL 10.0
- new bool:g_GameActive = false;
- new g_CountdownTime;
- new g_Answer[32]; // Changed to string to handle both numbers and text
- new bool:g_WinnerFound = false;
- new g_GameType;
- new g_NoResponseCount = 0;
- enum _:GameTypes {
- GAME_FIRSTWRITE = 1,
- GAME_GUESS,
- GAME_MATH
- }
- public plugin_init() {
- register_plugin("JB Challenges First", "1.0", "CheezPuff (Ariel)");
- // Register commands
- register_concmd("say /first", "CmdStartGame", ADMIN_FLAG); // פקודה להפעיל בצאט
- register_concmd("say /random", "CmdStartGame", ADMIN_FLAG); // פקודה להפעיל בצאט
- register_concmd("say /fw", "CmdStartGame", ADMIN_FLAG); // פקודה להפעיל בצאט
- register_clcmd("say", "HandleSay");
- register_clcmd("say_team", "HandleSay");
- set_task(CHECK_INTERVAL, "CheckTerroristCount", .flags="b");
- }
- public CheckTerroristCount(taskid) {
- if (g_GameActive)
- return;
- new tCount = get_team_count(CS_TEAM_T);
- if (tCount >= 9) {
- StartGameCountdown();
- }
- }
- public CmdStartGame(id, level, cid) {
- if (!cmd_access(id, level, cid, 1))
- return PLUGIN_HANDLED;
- if (g_GameActive) {
- client_print(id, print_chat, "[JB] A challenge is already in progress!");
- return PLUGIN_HANDLED;
- }
- new tCount = get_team_count(CS_TEAM_T);
- if (tCount < 2) {
- client_print(id, print_chat, "[JB] Need at least 2 terrorists to start a challenge!");
- return PLUGIN_HANDLED;
- }
- StartGameCountdown();
- return PLUGIN_HANDLED;
- }
- stock get_team_count(CsTeams:team) {
- new players[MAX_PLAYERS], num;
- get_players(players, num, "ae", team == CS_TEAM_T ? "TERRORIST" : "CT");
- return num;
- }
- public StartGameCountdown() {
- g_GameActive = true;
- g_WinnerFound = false;
- g_CountdownTime = 5;
- g_GameType = random_num(GAME_FIRSTWRITE, GAME_MATH);
- new gameTypeName[32];
- GetGameTypeName(g_GameType, gameTypeName, charsmax(gameTypeName));
- // Show countdown in HUD
- set_hudmessage(255, 255, 0, -1.0, 0.35, 0, 6.0, 12.0, 0.1, 0.1);
- show_hudmessage(0, "%s will start in 5 seconds", gameTypeName);
- set_task(1.0, "CountdownTimer", .flags="a", .repeat=5);
- }
- public CountdownTimer() {
- g_CountdownTime--;
- if (g_CountdownTime > 0) {
- // Show countdown numbers in HUD
- set_hudmessage(255, 0, 0, -1.0, 0.35, 0, 1.0, 1.0, 0.1, 0.1);
- show_hudmessage(0, "%d", g_CountdownTime);
- emit_sound(0, CHAN_VOICE, "fvox/doop.wav", 1.0, ATTN_NORM, 0, PITCH_NORM);
- } else {
- StartSelectedGame();
- remove_task();
- }
- }
- public StartSelectedGame() {
- switch(g_GameType) {
- case GAME_FIRSTWRITE: {
- new chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- new output[6];
- for (new i = 0; i < 5; i++) {
- output[i] = chars[random_num(0, strlen(chars) - 1)];
- }
- output[5] = 0;
- copy(g_Answer, charsmax(g_Answer), output);
- set_hudmessage(255, 255, 0, -1.0, 0.35, 0, CHALLENGE_TIMEOUT, 1.0);
- show_hudmessage(0, "First to write: %s", output);
- }
- case GAME_GUESS: {
- new num = random_num(1, 150);
- num_to_str(num, g_Answer, charsmax(g_Answer));
- set_hudmessage(255, 255, 0, -1.0, 0.35, 0, CHALLENGE_TIMEOUT, 1.0);
- show_hudmessage(0, "Guess the number between 1 and 150!");
- }
- case GAME_MATH: {
- new num1 = random_num(1, 50);
- new num2 = random_num(1, 50);
- new operation = random_num(1, 2);
- new result;
- if (operation == 1) {
- result = num1 + num2;
- num_to_str(result, g_Answer, charsmax(g_Answer));
- set_hudmessage(255, 255, 0, -1.0, 0.35, 0, CHALLENGE_TIMEOUT, 1.0);
- show_hudmessage(0, "Math Question: %d + %d = ?", num1, num2);
- } else {
- result = num1 - num2;
- num_to_str(result, g_Answer, charsmax(g_Answer));
- set_hudmessage(255, 255, 0, -1.0, 0.35, 0, CHALLENGE_TIMEOUT, 1.0);
- show_hudmessage(0, "Math Question: %d - %d = ?", num1, num2);
- }
- }
- }
- set_task(CHALLENGE_TIMEOUT, "EndGameNoWinner");
- }
- public HandleSay(id) {
- if (!g_GameActive || g_WinnerFound || !is_user_connected(id))
- return PLUGIN_CONTINUE;
- if (cs_get_user_team(id) != CS_TEAM_T) {
- client_print(id, print_chat, "[JB] Only terrorists can participate in challenges!");
- return PLUGIN_CONTINUE;
- }
- new said[32];
- read_args(said, charsmax(said));
- remove_quotes(said);
- trim(said);
- if (strlen(said) < 1)
- return PLUGIN_CONTINUE;
- switch(g_GameType) {
- case GAME_FIRSTWRITE: {
- if (equal(said, g_Answer, strlen(g_Answer))) {
- DeclareWinner(id, "First Write");
- }
- }
- case GAME_GUESS: {
- new guess = str_to_num(said);
- new answer = str_to_num(g_Answer);
- if (guess == answer) {
- DeclareWinner(id, "Number Guess");
- } else if (guess > 0 && guess <= 150) {
- client_print(id, print_chat, "[JB] %s! The number is %s",
- guess < answer ? "Higher" : "Lower",
- abs(guess - answer) <= 10 ? "very close" : "far");
- }
- }
- case GAME_MATH: {
- if (str_to_num(said) == str_to_num(g_Answer)) {
- DeclareWinner(id, "Math");
- }
- }
- }
- return PLUGIN_CONTINUE;
- }
- public DeclareWinner(id, const gameType[]) {
- if (g_WinnerFound || !is_user_connected(id))
- return;
- g_WinnerFound = true;
- g_GameActive = false;
- g_NoResponseCount = 0;
- // Move to CT team and respawn
- cs_set_user_team(id, CS_TEAM_CT);
- ExecuteHamB(Ham_CS_RoundRespawn, id);
- new name[32];
- get_user_name(id, name, charsmax(name));
- client_print(0, print_chat, "[JB] %s has won the %s challenge and moved to CT!", name, gameType);
- remove_task();
- set_task(5.0, "CheckTerroristCount");
- }
- public EndGameNoWinner() {
- if (!g_GameActive)
- return;
- g_GameActive = false;
- g_NoResponseCount++;
- client_print(0, print_chat, "[JB] Time's up! No one won the challenge.");
- if (g_NoResponseCount >= 2) {
- client_print(0, print_chat, "[JB] Starting a new challenge automatically...");
- g_NoResponseCount = 0;
- set_task(3.0, "StartGameCountdown");
- }
- set_task(5.0, "CheckTerroristCount");
- }
- GetGameTypeName(type, output[], len) {
- switch(type) {
- case GAME_FIRSTWRITE: copy(output, len, "First Write Challenge");
- case GAME_GUESS: copy(output, len, "Number Guess Challenge");
- case GAME_MATH: copy(output, len, "Math Challenge");
- default: copy(output, len, "Unknown Challenge");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement