I am basically trying to set a random number to each player and also making sure it doesn't equal anyone else's number. It works of course, but my server is crashing. I know this because when i comment this function out, crashes don't exist. Is there a more efficient way of doing this? Thanks in advance.
Code:
public round_start() set_numbers()
// ============= Assigns a random number to each player ==================
set_numbers()
{
new alive_humans = get_alivehumans()
// Give Players random suspect #. If the same number as anyone else, redo loop.
for(new i = 1; i <= maxplayers; i++)
{
if(is_user_alive(i))
{
if(PlayerInfo[i] == HUMAN)
{
pnumber[i] = random_num(1, alive_humans)
for(new j = i - 1; j >= 1; j--)
{
if(pnumber[i] == pnumber[j])
{
i--
break
}
}
}
}
}
}
get_alivehumans()
{
new alive_humans
alive_humans = 0
for(new id = 1; id <= maxplayers; id++)
{
if (is_user_alive(id) && PlayerInfo[id] == HUMAN)
alive_humans++
}
return alive_humans
}