SA-MP Forums Archive
Which one of these 2 commands would be most efficient? - 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: Which one of these 2 commands would be most efficient? (/showthread.php?tid=396387)



Which one of these 2 commands would be most efficient? - andrew2695 - 30.11.2012

Hello, I have 2 ways of making the commands but I would want to know which one is the best. They both work.

Command 1 Example:
pawn Код:
CMD:fix(playerid, params[])
{
    new target, string[80];
    if(sscanf(params, "u", target)) target = playerid;
    if (!IsPlayerConnected(target)) return SendClientMessageFormatted(playerid, COLOR_DARKRED, "%s is not connected to the server.", params);
    if(!IsPlayerInAnyVehicle(target))
    {
        if(target != playerid)
        {
            SendClientMessageFormatted(playerid, COLOR_DARKRED, "%s(%d) is not in a vehicle.",Name(target),target);
        }
        else
        {
            SendClientMessage(playerid, COLOR_DARKRED, "You must be in a vehicle to use this command.");
        }
        return 1;
    }
    if(IsPlayerInAnyVehicle(target))
    {
        new vid;
        vid = GetPlayerVehicleID(target);
        RepairVehicle(vid);
        if(target != playerid)
        {
            format(string, 128, "You repaired %s(%d)'s vehicle.", Name(target), target);
            SendClientMessage(playerid, COLOR_ADMIN, string);
        }
        else
        {
            SendClientMessage(playerid, COLOR_ADMIN, "Your vehicle has been fixed.");
        }
    }
    return 1;
}

Command 2 Example:
pawn Код:
CMD:fix(playerid, params[])
{
    new target, string[80], vid;
    if(sscanf(params, "u", target))
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_DARKRED, "You must be in a vehicle to use this command.");
        SendClientMessage(playerid, COLOR_ADMIN, "Your vehicle has been fixed.");
        RepairVehicle(vid);
    }
    else
    {
        if (!IsPlayerConnected(target)) return SendClientMessageFormatted(playerid, COLOR_DARKRED, "%s is not connected to the server.", params);
        if(!IsPlayerInAnyVehicle(target)) return SendClientMessageFormatted(playerid, COLOR_DARKRED, "%s(%d) is not in a vehicle.",Name(target),target);
        vid = GetPlayerVehicleID(playerid);
        format(string, 128, "You repaired %s(%d)'s vehicle.", Name(target), target);
        SendClientMessage(playerid, COLOR_ADMIN, string);
        RepairVehicle(vid);
    }
    return 1;
}



Re: Which one of these 2 commands would be most efficient? - DaRoderick - 30.11.2012

Command 2 seems like the faster one to process?


Re: Which one of these 2 commands would be most efficient? - InfiniTy. - 30.11.2012

The 2nd command.