Spectating a random player -
Michael@Belgium - 11.04.2011
Lol i don't know it this works ... but i don't know much about random()
pawn Код:
for(new i; i<MAX_PLAYERS; i++)
{
new randomplayer = random(30);
TogglePlayerSpectating(playerid, 1);
PlayerSpectateVehicle(playerid,randomplayer);
}
I don't think this is working ... i can't test it right now xd
plz help me
UPDATE:
pawn Код:
new randomplayer = Iter_Random(Player);
TogglePlayerSpectating(playerid, 1);
PlayerSpectateVehicle(playerid,GetPlayerVehicleID(randomplayer));
THIS SHOULD WORK ?!
Re: Spectating a random player -
iggy1 - 11.04.2011
Have you got 30 players on your server when testing? The random function in your script will just get a random number 0 - 29, it doesn't check if the player is actually connected. Easiest way i can think of is using foreach.
pawn Код:
new randomplayer = Iter_Random(Player);
Re: Spectating a random player -
Michael@Belgium - 11.04.2011
Quote:
Originally Posted by iggy1
Have you got 30 players on your server when testing? The random function in your script will just get a random number 0 - 29, it doesn't check if the player is actually connected. Easiest way i can think of is using foreach.
pawn Код:
new randomplayer = Iter_Random(Player);
|
hah
ok ... so now it must work ?!
Re: Spectating a random player -
iggy1 - 11.04.2011
pawn Код:
#include <foreach>//you need this include
new randomplayer = Iter_Random(Player);
TogglePlayerSpectating(playerid, 1);
PlayerSpectateVehicle(playerid,randomplayer);
You will want to do some additional checks to make sure you don't spec yourself ect.
Re: Spectating a random player -
Mean - 11.04.2011
Well
pawn Код:
r:new randomplayer = random(MAX_PLAYERS); // Instead of 30, put MAX_PLAYERS
if( IsPlayerConnected( randomplayer ) && randomplayer != playerid )
{
TogglePlayerSpectating(playerid, 1);
PlayerSpectateVehicle(playerid, GetPlayerVehicleID( randomplayer ) );
}
else goto r;
Checking if it's connected.
Re: Spectating a random player -
iggy1 - 11.04.2011
Thats not very nice code though foreach is much better than that in every way. You dont even need to loop. That code is actually extremly inefficient especially if only a few players are connected.
Re: Spectating a random player -
Michael@Belgium - 11.04.2011
Quote:
Originally Posted by iggy1
pawn Код:
#include <foreach>//you need this include
new randomplayer = Iter_Random(Player); TogglePlayerSpectating(playerid, 1); PlayerSpectateVehicle(playerid,randomplayer);
You will want to do some additional checks to make sure you don't spec yourself ect.
|
No i think i don't need to add some code ...
pawn Код:
public OnPlayerSpawn(playerid)
{
if(EndRoundCounter != 0)//if the round is busy ..
{
SendClientMessage(playerid, COLOR_RED,"Sorry, you can't join while the round is in progress, you have to wait ...");
SendClientMessage(playerid, COLOR_ORANGE,"While you have to wait, you can specate some players");
GameTextForPlayer(playerid, "~y~Round in progress ...", 1250, 3);
for(new i; i<MAX_PLAYERS; i++)
{
new randomplayer = Iter_Random(Player);
TogglePlayerSpectating(playerid, 1);
PlayerSpectateVehicle(playerid,randomplayer);
}
}
//.....
Im using it under OnPlayerSpawn()
Re: Spectating a random player -
Mean - 11.04.2011
Yeh, I deleted the loop.
EDIT: Shoudn't that "playerid" in TooglePlayerSpectating be "i" and all the other "playerid"s?
Re: Spectating a random player -
iggy1 - 11.04.2011
micheal you dont need that loop you are not even using the var 'i'.
Re: Spectating a random player -
Michael@Belgium - 11.04.2011
Quote:
Originally Posted by Mean
Yeh, I deleted the loop.
EDIT: Shoudn't that "playerid" in TooglePlayerSpectating be "i" and all the other "playerid"s?
|
Quote:
Originally Posted by iggy1
micheal you dont need that loop you are not even using the var 'i'.
|
ah lol Xd
So just this:
pawn Код:
new randomplayer = Iter_Random(Player);
TogglePlayerSpectating(playerid, 1);
PlayerSpectateVehicle(playerid,randomplayer);