some questions
#1

1. Which one is better at performance?

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

pawn Код:
stock GetPlayerIDFromName(name[])
{
    foreach(Player, i)
    {
        if(!strcmp(GetPlayerNameEx(i), name, false)) return i;
    }
}
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

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);
OR

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;
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 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;
}
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
Use sscanf's "u" parameter to get an ID from a name.

As for the second question - store the data in a variable if you are going to be using it more than once.
For param, no, it wont work as I want. For example, how I use this function:

pawn Код:
if(GetPlayerIDFromName(name) != INVALID_PLAYER_ID)
{
    Job[GetPlayerIDFromName(name)] = 0;
    blablabla
}
else
{
    // player is offline, send a mysql query by "name"
}
Thanks for second question answer
Reply
#3

You mean...

pawn Код:
new name[24], id;
sscanf(name, "u", id);
if (id != INVALID_PLAYER_ID)
{
    Job[id] = 0;
    blablabla
}
else
{
    // player is offline, send a mysql query by "name"
}


Damn, I dont get it
Reply
#4

My example is not "full", lol:

pawn Код:
new name[24];
if(sscanf(something, "s[24]", name)) return <...>
if(GetPlayerIDFromName(name) == INVALID_PLAYER_ID)
{
    // mysql query
}
else
{
     // player is online, do something
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)