Hello. The following plugin makes it possible for bots to be forced to buy items from the humans' Extra Items menu:
PHP Code:
#include <amxmodx>
#include <zombie_plague_advance>
/*================================================================================
[Plugin Customization]
=================================================================================*/
// Items name (note: add exact item name)
new const EXTRA_ITEMS[][] = {
"Plasma Gun",
"Golden Ak 47",
"Item3"
}
/*================================================================================
Customization ends here! Yes, that's it. Editing anything beyond
here is not officially supported. Proceed at your own risk...
=================================================================================*/
enum
{
TASK_STARTGIVE = 298,
TASK_GIVEITEM
}
#define ID_BOT (taskid - TASK_GIVEITEM)
new cvar_max_bots, g_botname[33][32], g_has_item[33], g_maxplayers;
public plugin_init()
{
/* Plugin register */
register_plugin("[ZP] Bot Addon: Force buy items", "v0.2", "Crazy");
/* Cvars */
cvar_max_bots = register_cvar("zp_force_buy_maxbots", "5");
/* Max players */
g_maxplayers = get_maxplayers()
}
public client_putinserver(id)
{
if (is_user_bot(id))
get_user_name(id, g_botname[id], charsmax(g_botname[]));
}
public zp_round_started(gamemode, id)
{
for (new id = 1; id <= g_maxplayers; id++)
g_has_item[id] = false;
if (gamemode != MODE_PLAGUE || MODE_SURVIVOR)
set_task(2.0, "give_item_task", TASK_STARTGIVE);
}
public give_item_task(taskid)
{
static id, iBots, iMaxBots;
iBots = 0;
iMaxBots = get_pcvar_num(cvar_max_bots);
while (iBots <= iMaxBots)
{
id = get_random_bot(random_num(1, get_alive_bots()));
if (!is_user_alive(id))
continue;
if (zp_get_user_zombie(id))
continue;
if (g_has_item[id])
continue;
set_task(1.0, "give_item", id+TASK_GIVEITEM);
iBots++;
}
remove_task(TASK_STARTGIVE);
remove_task(TASK_GIVEITEM);
}
public give_item(taskid)
{
static id, random, itemid;
id = ID_BOT;
random = random_num(0, sizeof EXTRA_ITEMS - 1);
itemid = zp_get_extra_item_id(EXTRA_ITEMS[random]);
if (itemid == -1)
{
set_task(0.5, "give_item", id+TASK_GIVEITEM);
return;
}
zp_force_buy_extra_item(id, itemid, 1);
g_has_item[id] = true;
remove_task(id+TASK_GIVEITEM);
}
get_alive_bots()
{
static iBot, id;
iBot = 0;
for (id = 1; id <= g_maxplayers; id++)
{
if (is_user_alive(id) && is_user_bot(id))
iBot++;
}
return iBot;
}
get_random_bot(n)
{
static iBot, id;
iBot = 0;
for (id = 1; id <= g_maxplayers; id++)
{
if (is_user_alive(id) && is_user_bot(id))
iBot++;
if (iBot == n)
return id;
}
return -1;
}
In the following code, you need to type the names of the extra items you want the bots to have access to:
Code:
// Items name (note: add exact item name)
new const EXTRA_ITEMS[][] = {
"Plasma Gun",
"Golden Ak 47",
"Item3"
}
The problem is that the plugin works only during normal infection round, Nemesis mode, Assassin mode, Swarm mode, Multiple infection mode, Plague mode, Armageddon mode, but makes the server to crash during Survivor mode and Sniper mode. During Armageddon round and Plague round, there are survivors, too, but then the server doesn't crash. The server crash only when the game mode is mode where there is only one Sniper or only one Survivor, and all other players are zombies. Can someone fix this bug? I'm using ZPA 1.6.1.
If you are going to help me, don't forget to explain to me what code(s) exactly you edited, so i can learn for myself.
Thanks.