SA-MP Forums Archive
Returning wrong number - 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: Returning wrong number (/showthread.php?tid=516539)



Returning wrong number - Yako - 31.05.2014

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;
}



Re: Returning wrong number - Aerotactics - 31.05.2014

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



Re: Returning wrong number - Copfan5 - 31.05.2014

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.


Re: Returning wrong number - Abagail - 31.05.2014

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


Re: Returning wrong number - Jefff - 31.05.2014

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;
}