Here a better + fixed function to get a random bot with no replication!!
I saw alot of coders struggle to create such function there you go, try understanding...
PHP Code:
get_random_bot(arrNoReplicate[MAX_PLAYERS]="", &ReplicateSize=0)
{
static iPlayers[MAX_PLAYERS], iNum;
get_players(iPlayers, iNum, "adh");
if( ReplicateSize )
{
for(new i, j; j < iNum; j++)
{
for(i = 0; i < ReplicateSize; i++)
{
if(iPlayers[ j ] == arrNoReplicate[ i ])
iPlayers[ j-- ] = iPlayers [ --iNum ];
}
}
}
if(!iNum) // uncomment and remove return 0; in the following if you want the function to never fails until legitimately there are no alive bots exists.
{
//ReplicateSize = 0;
//get_players(iPlayers, iNum, "adh");
return 0;
}
new iChosen = 0;
if( iNum > 0 )
{
iChosen = iPlayers[ random(iNum) ] ;
if(MAX_PLAYERS > ReplicateSize) arrNoReplicate [ ReplicateSize++ ] = iChosen;
}
return iChosen;
}
This how to use inside the following function...
PHP Code:
public give_item_task(taskid)
{
static iMaxBots;
iMaxBots = get_pcvar_num(cvar_max_bots);
for (new i, id, oldbots[MAX_PLAYERS], oldbots_count; i < iMaxBots; i++)
{
if(! (id = get_random_bot(oldbots, oldbots_count)) )
break;
if (zp_get_user_zombie(id))
continue;
if (g_has_item[id])
continue;
set_task(1.0, "give_item", id+TASK_GIVEITEM);
}
}
__________________