Skip the other game modes too + what natsheh said above.
Code:
public zp_round_started(gamemode, id)
{
for (new id = 1; id <= g_maxplayers; id++)
g_has_item[id] = false;
if (gamemode != MODE_PLAGUE && gamemode != MODE_SURVIVOR && gamemode != MODE_SNIPER ) // etc...
set_task(2.0, "give_item_task", TASK_STARTGIVE);
}
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 && gamemode != MODE_SURVIVOR && gamemode != MODE_SNIPER)
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);
/* Why do you loop here? You can create an infinite loop because not everytime botid will be different. */
for (new i; i <= iMaxBots; i++)
{
id = get_random_bot(i);
// We dont have any more bots, break the loop
if(id == -2)
break;
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_random_bot(index)
{
new iPlayers[MAX_PLAYERS], iNum;
get_players(iPlayers, iNum, "ad");
if(iNum < index)
return -2;
return iNum > 0 ? iPlayers[index] : -1;
}