/* Coding and Idea by Dest 'Des12' Romano */
#include <amxmodx>
#include <amxmisc>
#pragma semicolon 1
#define ADMIN_LEVEL ADMIN_BAN
#define ADMIN_LEVEL_COMMAND ADMIN_RCON
#define PNAME Random
new g_num;
public plugin_init() {
register_plugin("Random Plugin","v1","Dest Romano");
register_cvar("random_selfimmune","1");
register_cvar("random_adminsimmune","1");
register_clcmd("amx_randomnumber","randomNum",ADMIN_LEVEL," - <public/private/player/admins> <min> <max> [statement] [command]");
register_clcmd("amx_randomplayer","randomPlayer",ADMIN_LEVEL," - <public/private/player/admins> [statement] [command]");
server_cmd("exec addons/amxmodx/configs/random.cfg");
}
public randomNum(id) {
if(!(get_user_flags(id) & ADMIN_LEVEL)) {
client_print(id,print_console,"[PNAME] You do not have access to this!");
return PLUGIN_HANDLED;
}
new minarg[32], maxarg[32], printarg[32], command[32],statement[76];
new minnum, maxnum, printmode = 0, player;
read_argv(1, printarg, 31);
read_argv(2, minarg, 31);
read_argv(3, maxarg, 31);
read_argv(4, statement, 75);
read_argv(5, command, 31);
remove_quotes(statement);
if(read_argc() < 4) {
client_print(id,print_chat,"[PNAME] Usage: amx_randomnumber - <public/private/player/admins> <min> <max> [statement] [command]");
return PLUGIN_HANDLED;
}
minnum = str_to_num(minarg);
maxnum = str_to_num(maxarg);
if(equal(printarg,"public"))
printmode = 1;
else if(equal(printarg,"private"))
printmode = 2;
else if(equal(printarg,"admins"))
printmode = 3;
else {
player = cmd_target(id, printarg, 4);
if(!is_user_connected(player)) {
client_print(id,print_console,"[PNAME] Invalid player!");
return PLUGIN_HANDLED;
}
printmode = 4;
}
if(!equal(command,"") && !(get_user_flags(id) & ADMIN_LEVEL_COMMAND)) {
client_print(id,print_console,"[PNAME] You do not have access to using a command! Try without the [command] section.");
return PLUGIN_HANDLED;
}
new num = random_num(minnum, maxnum);
new name[32];
get_user_name(id, name, 31);
new cvar = get_cvar_num("amx_show_activity");
if(cvar == 1)
client_print(0,print_chat,"[PNAME] An Admin initialized the Random Generator:^n");
if(cvar == 2) {
client_print(0,print_chat,"[PNAME] ADMIN %s initialized the Random Generator:^n",name);
}
log_amx("[PNAME] ADMIN %s initialized the Random Generator!",name);
switch(printmode) {
case 1:
client_print(0,print_chat,"[PNAME] Public: %s %i",statement,num);
case 2:
client_print(id,print_chat,"[PNAME] Private: %s %i",statement,num);
case 3: {
new players[32];
get_players(players,g_num,"c");
for(new i = 0; i < g_num; i++) {
new admin = players[i];
if(is_user_admin(admin))
client_print(admin,print_chat,"[PNAME] Admin: %s %i",statement,num);
}
}
case 4: {
client_print(id,print_chat,"[PNAME] User-to-User: %s %i",statement,num);
client_print(player,print_chat,"[PNAME] User-to-User: %s %i",statement,num);
}
}
if(!equal(command,"")) {
server_cmd("%s %i",command,num);
}
return PLUGIN_HANDLED;
}
public randomPlayer(id) {
if(!(get_user_flags(id) & ADMIN_LEVEL)) {
client_print(id,print_console,"[PNAME] You do not have access to this!");
return PLUGIN_HANDLED;
}
new printarg[32], command[32], statement[76];
new printmode = 0, player;
read_argv(1, printarg, 31);
read_argv(2, statement, 75);
read_argv(3, command, 31);
remove_quotes(command);
remove_quotes(statement);
if(read_argc() < 2) {
client_print(id,print_chat,"[PNAME] Usage: amx_randomplayer - <public/private/player/admins> [statement] [command]");
return PLUGIN_HANDLED;
}
if(!equal(command,"") && !(get_user_flags(id) & ADMIN_LEVEL_COMMAND)) {
client_print(id,print_console,"[PNAME] You do not have access to using a command! Try without the [command] section.");
return PLUGIN_HANDLED;
}
if(equal(printarg,"public"))
printmode = 1;
else if(equal(printarg,"private"))
printmode = 2;
else if(equal(printarg,"admins"))
printmode = 3;
else {
player = cmd_target(id, printarg, 4);
if(!is_user_connected(player)) {
client_print(id,print_console,"[PNAME] Invalid player!");
return PLUGIN_HANDLED;
}
printmode = 4;
}
new randomplayer = randPlayer(id);
if(randomplayer == 100) return PLUGIN_HANDLED;
new name[32];
get_user_name(id, name, 31);
new randomname[32];
get_user_name(randomplayer, randomname, 31);
new cvar = get_cvar_num("amx_show_activity");
if(cvar == 1)
client_print(0,print_chat,"[PNAME] An Admin initialized the Random Generator:^n");
if(cvar == 2) {
client_print(0,print_chat,"[PNAME] ADMIN %s initialized the Random Generator:^n",name);
}
log_amx("[PNAME] ADMIN %s initialized the Random Generator!",name);
switch(printmode) {
case 1:
client_print(0,print_chat,"[PNAME] Public: %s %s",statement,randomname);
case 2:
client_print(id,print_chat,"[PNAME] Private: %s %s",statement,randomname);
case 3: {
new players[32];
get_players(players,g_num,"c");
for(new i = 0; i < g_num; i++) {
new admin = players[i];
if(is_user_admin(admin))
client_print(admin,print_chat,"[PNAME] Admin: %s %s",statement,randomname);
}
}
case 4: {
client_print(id,print_chat,"[PNAME] User-to-User: %s %s",statement,randomname);
client_print(player,print_chat,"[PNAME] User-to-User: %s %s",statement,randomname);
}
}
if(!equal(command,"")) {
server_cmd("%s ^"%s^"",command,randomname);
}
return PLUGIN_HANDLED;
}
stock randPlayer(id) {
new selfimmune = get_cvar_num("random_selfimmune");
new adminsimmune = get_cvar_num("random_adminsimmune");
new maxp = get_maxplayers();
new player, trys = 0;
while(!is_user_connected(player)) {
trys++;
if(trys > maxp) {
client_print(id,print_chat,"[PNAME] All players in the server are immune!");
return 100;
}
player = random_num(1,maxp);
if(selfimmune && player == id) player = -1;
if(adminsimmune && is_user_admin(player)) player = -1;
}
return player;
}