Untitled
unknown
plain_text
a year ago
3.3 kB
6
Indexable
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <color>
#include <string>
#define MAX_PLAYERS 32
#define BOMB_TIMER 10.0
new g_bombCarrier = -1;
new g_bombTime[MAX_PLAYERS + 1];
new g_bombActive = 0;
public plugin_init() {
register_plugin("Ticking Bomb", "1.0", "Your Name");
register_clcmd("say !startbomb", "cmd_start_bomb");
}
public cmd_start_bomb(id) {
if (!is_user_alive(id)) return;
// Check if a bomb game is already active
if (g_bombActive) {
client_print(id, print_chat, "A bomb game is already in progress!");
return;
}
// Randomly select a prisoner to carry the bomb
g_bombCarrier = get_random_prisoner(id);
if (g_bombCarrier == -1) {
client_print(id, print_chat, "No prisoners available to select!");
return;
}
// Set the bomb active
g_bombActive = 1;
g_bombTime[g_bombCarrier] = BOMB_TIMER;
// Notify players
client_print(0, print_chat, "The bomb has been given to player %d! They have %.1f seconds to pass it!", g_bombCarrier, BOMB_TIMER);
set_task(1.0, "bomb_timer_task");
}
public bomb_timer_task() {
if (g_bombActive) {
// Decrease the timer
g_bombTime[g_bombCarrier] -= 1.0;
// Check if the timer has expired
if (g_bombTime[g_bombCarrier] <= 0) {
// Bomb exploded
client_print(0, print_chat, "Player %d has exploded!", g_bombCarrier);
// Reset game
reset_bomb_game();
return;
}
// Continue the timer
set_task(1.0, "bomb_timer_task");
}
}
public client_cmd(id, const cmd[]) {
if (strcmp(cmd, "say !passbomb") == 0) {
if (g_bombActive && id == g_bombCarrier) {
// Find the target to pass the bomb to
new target = find_target(id);
if (target != -1) {
// Pass the bomb
g_bombCarrier = target;
g_bombTime[g_bombCarrier] = BOMB_TIMER;
client_print(0, print_chat, "Player %d has passed the bomb to player %d! They have %.1f seconds to pass it!", id, g_bombCarrier, BOMB_TIMER);
} else {
client_print(id, print_chat, "No valid target to pass the bomb to!");
}
} else {
client_print(id, print_chat, "You are not the bomb carrier!");
}
}
}
public reset_bomb_game() {
g_bombActive = 0;
g_bombCarrier = -1;
for (new i = 1; i <= MAX_PLAYERS; i++) {
g_bombTime[i] = 0;
}
}
public get_random_prisoner(exclude_id) {
new prisoners[MAX_PLAYERS];
new count = 0;
for (new i = 1; i <= MAX_PLAYERS; i++) {
if (is_user_alive(i) && i != exclude_id) {
prisoners[count++] = i;
}
}
if (count > 0) {
return prisoners[random_num(0, count - 1)];
}
return -1;
}
public find_target(id) {
new target = -1;
// Here you can implement your logic to find a target prisoner
// For example, you could randomly select another player who is alive
for (new i = 1; i <= MAX_PLAYERS; i++) {
if (is_user_alive(i) && i != id) {
target = i;
break; // Just select the first valid target
}
}
return target;
}Editor is loading...