05.09.2011, 14:18
1. Which one is better at performance?
OR just
2. Its better to store function value (for example - GetClosestVehicle) into a variable and then use it, or just use the function?
I mean, for example
OR
NOTE: this is JUST example, Im asking because I have ~3 scripts writen like example nr. 1.
Im using GetClosestVehicle function by RyDeR`:
pawn Код:
stock GetPlayerIDFromName(name[]) // by ipleomax afaik lol
{
foreach(Player, i)
{
if(strfind(GetPlayerNameEx(i), name, true) != -1 && strlen(name) != 0) return i;
}
if(strfind(name, "0", true) != -1 && strlen(name) <= 1) return 0;
if(strval(name) > 0 && strval(name) <= MAX_PLAYERS) return strval(name);
return INVALID_PLAYER_ID;
}
pawn Код:
stock GetPlayerIDFromName(name[])
{
foreach(Player, i)
{
if(!strcmp(GetPlayerNameEx(i), name, false)) return i;
}
}
I mean, for example
pawn Код:
if(GetClosestVehicle(playerid, 5) == INVALID_VEHICLE_ID) return BLABLABLA
new str[lenght];
format(str, lenght, "%s %s %d", ENUM[GetClosestVehicle(playerid, 5)][string], ENUM[GetClosestVehicle(playerid, 5)][string2], ENUM[GetClosestVehicle(playerid, 5)][int]);
SendClientMessage(playerid, -1, str);
vehid[playerid] = GetClosestVehicle(playerid, 5);
pawn Код:
new closestveh = GetClosestVehicle(playerid, 5);
if(closestveh == INVALID_VEHICLE_ID) return BLABLABLA
new str[lenght];
format(str, lenght, "%s %s %d", ENUM[closestveh][string], ENUM[closestveh][string2], ENUM[closestveh][int]);
SendClientMessage(playerid, -1, str);
vehid[playerid] = closestveh;
Im using GetClosestVehicle function by RyDeR`:
pawn Код:
stock GetClosestVehicle(playerid, Float:fRadius)
{
new
iClosestID = INVALID_VEHICLE_ID,
Float:fFinalDistance,
Float:fDistance,
Float:fX,
Float:fY,
Float:fZ;
GetPlayerPos(playerid, fX, fY, fZ);
fFinalDistance = fRadius;
for(new i; i != Cars; ++i)
{
if((fDistance = GetVehicleDistanceFromPoint(i, fX, fY, fZ)) < fFinalDistance)
{
fFinalDistance = fDistance;
iClosestID = i;
}
}
return iClosestID;
}