PDA

View Full Version : Which one of these 2 commands would be most efficient?


andrew2695
30/11/2012, 06:17 PM
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:
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:

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

DaRoderick
30/11/2012, 06:19 PM
Command 2 seems like the faster one to process?

InfiniTy.
30/11/2012, 06:40 PM
The 2nd command.