Returning wrong number
#1

Hello, why this script returns me 2000?

Код:
stock GetPlayerVehicles(playerid)
{
 	new count = 0;
	for(new i = 0; i < MAX_VEHICLES; i++)
	{
 		if(strcmp(vInfo[i][Owner], GetPlayerNameEx(playerid)) == 0)
		count++;
	}
	return count;
}
Reply
#2

Try:
pawn Код:
if(strcmp(vInfo[i][Owner], GetPlayerNameEx(playerid),false) == 0){count++;}
Reply
#3

The issue is it runs all the time until It equals or is greater then MAX VEHICLES. Try making a new define for the most number of vehicles someone can have and use that.
Reply
#4

MAX_VEHICLES is 2000... Notice anything? Its returning the amount of vehicles allowed.
Reply
#5

because if [Owner] is empty strcmp returns 0 (match)

pawn Код:
stock GetPlayerVehicles(playerid)
{
    new Nick[MAX_PLAYER_NAME], count = 0;
    Nick = GetPlayerNameEx(playerid);
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        if(vInfo[i][Owner][0] != '\0' && strcmp(vInfo[i][Owner], Nick) == 0)
            count++;
    }
    return count;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)