Choosing a random player bug - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Choosing a random player bug (
/showthread.php?tid=620956)
Choosing a random player bug -
TroubleFingers - 05.11.2016
Hey, I registered an account as I browse this forum a lot. So, let's get to the point. This is my code:
PHP код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(pInEvent[i] == 1)
{
new president = random(i);
if(president == playerid)
{
SetPlayerSkin(playerid, 228);
GivePlayerWeapon(playerid, 24, 99999);
}
else if(president != playerid)
{
SetPlayerSkin(playerid, 165);
GivePlayerWeapon(playerid, 23, 99999);
}
Basically this should choose a random player as the president and the rest of the people as the agents. I already made the event commands etc but this block of code is my problem.
Any fix?
Re: Choosing a random player bug -
SyS - 05.11.2016
What is the problem?
And your code has no logic.
Re: Choosing a random player bug -
Logic_ - 05.11.2016
PHP код:
CheckPlayers(status)
{
new players;
for(new p, o = GetPlayerPoolSize(); p <= o; p++)
{
if(IsPlayerConnected(p))
{
switch(status)
{
case 0:
{
players ++;
}
case 1:
{
if(pInEvent[p])
{
players ++;
}
}
}
}
}
return players;
}
//
// at the top right after the includes, there where the variables belong...
new president = -1;
/* C O D E */
for(new i, l = GetPlayerPoolSize(); i <= l; i++) // loop
{
if(IsPlayerConnected(i)) // checks for connected
{
if(pInEvent[i])
{
if(president == -1)
{
president = CheckPlayers(1);
}
if(president == playerid)
{
SetPlayerSkin(playerid, 228);
GivePlayerWeapon(playerid, 24, 99999);
}
else if(president != playerid)
{
SetPlayerSkin(playerid, 165);
GivePlayerWeapon(playerid, 23, 99999);
}
}
}
}
/* C O D E */
Here you go.