21.07.2013, 17:36
Try this:
Read the comments!
EDIT: Sorry, missed a few things and adjusted accordingly.
pawn Код:
dcmd_load(playerid,params[])
{
new
// I removed your string and chk variables; you don't even use them here!
iVehID = GetPlayerVehicleID(playerid), // added a variable to serve as the player's vehicle ID; this way you don't have to call the function 3 times
rand,
mrand;
// I declared rand and mrand since there's no sense in defining them locally if you're going to need to define them in two places
if(!strlen(params)) // you didn't need to use sscanf if you're only dealing with a single string
return SendClientMessage(playerid, COLOR_ERROR, "usage: /load legal/ilegal");
if(strcmp(params, "legal") || strcmp(params, "ilegal")) // no reason to use == 1, it's redundant
return SendClientMessage(playerid,COLOR_ERROR,"usage: /load legal/ilegal");
switch(GetVehicleModel(iVehID)) // use a switch statement, it's faster and far better looking
{
case 403, 514, 515: // if the vehicle's model is either 403, 514, or 515, do the code below:
{
if(!strcmp(params, "legal"))
{
Crcp[playerid] = 2;
HasTruckLoaded[playerid]=1;
rand = random(sizeof(RandomTruckPoint));
SetPlayerRaceCheckpoint( playerid, 2,RandomTruckPoint[rand][0],RandomTruckPoint[rand][1],RandomTruckPoint[rand][2], 0, 0, 0 ,2 );
mrand = 50000 + random(500);
}
else if(!strcmp(params, "ilegal"))
{
Crcp[playerid] = 2;
HasTruckLoaded[playerid]=1;
rand = random(sizeof(RandomTruckPoint));
SetPlayerRaceCheckpoint( playerid, 2,RandomTruckPoint[rand][0],RandomTruckPoint[rand][1],RandomTruckPoint[rand][2], 0, 0, 0 ,2 );
mrand = 100000 + random(1000);
}
}
default: return 1; // if it's not one of those model ID's, end the processing on the command. "default" is basically "else" in an if-else control structure
}
return 1;
}
EDIT: Sorry, missed a few things and adjusted accordingly.