Looping players only effects player 0? -
serj009 - 17.07.2013
SO i have the following code that is under OnPlayerClickTextdraw as a button. When a player is in a vehicle, viewing the textdraws and clicks on this textdraw, it will send all other players in a vehicle viewing the textdraws a message.
Код:
for(new driver = 0 ; driver < MAX_PLAYERS; driver++)
{
if(PlayerLogged[driver] == 1 && PlayerViewingComputer[driver] == 0 && VehicleData[vehicleid][HasComputer] == 1)
{
SendClientMessage(driver,COLOUR_BLUE,"Test Message.");
return 1;
}
}
But, what's happening is that only player with the id of 0 is recieiving the ClientMessage. I am not really sure what is wrong, advise would be much appreciated. Thanks
Re: Looping players only effects player 0? -
Andriensis - 17.07.2013
you forgot the ";" between driver <MAX_PLAYERS and driver++
Re: Looping players only effects player 0? -
serj009 - 17.07.2013
Quote:
Originally Posted by Andriensis
you forgot the ";" between driver <MAX_PLAYERS and driver++
|
Good eye, Sorry that was a mistake copying over the code here. It's fixed.
Re: Looping players only effects player 0? -
RajatPawar - 17.07.2013
pawn Код:
public OnPlayerClickTextDraw(...)
{
if(IsPlayerInAnyVehicle(playerid))
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInVehicle(i, GetPlayerVehicleID(playerid))
{
SHOW HIM THE TEXTDRAW
}
}
...
Re: Looping players only effects player 0? -
iggy1 - 17.07.2013
Remove "return 1" from inside the loop, or else it will only send the 1st player (that matches the 'if' statement) the message. When you 'return' from inside a loop, it ends the loop.
Re: Looping players only effects player 0? -
serj009 - 17.07.2013
Thank's for the response guys, I have removed the return from the code however that did nothing.
Re: Looping players only effects player 0? -
iggy1 - 17.07.2013
If that didn't help, print the values of the variables used in the 'if' statement, they must hold incorrect values.
pawn Код:
for(new driver = 0 ; driver < MAX_PLAYERS; driver++)
{
printf( "playerid (%d) : PlayerLogged (%d) : PlayerViewingComputer (%d) : Has Computer (%d)",
driver,
PlayerLogged[driver],
PlayerViewingComputer[driver],
VehicleData[vehicleid][HasComputer]
);
if(PlayerLogged[driver] == 1 && PlayerViewingComputer[driver] == 0 && VehicleData[vehicleid][HasComputer] == 1)
{
SendClientMessage(driver,COLOUR_BLUE,"Test Message.");
}
}
The only possible explanation (once the return is removed) is that the vars hold the wrong values.