command option problem - 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: command option problem (
/showthread.php?tid=452453)
command option problem -
omidi - 21.07.2013
hi , problem is if you type /load asdm , it will show checkpoint
other issue is i want if i type /load legal give me 5000 cash etc and /load ilegal , gives 4000
Код:
dcmd_load(playerid,params[])
{
new string[128],chk[64];
if(sscanf(params, "s[32]", chk))
{
SendClientMessage(playerid, COLOR_ERROR, "usage: /load legal - ilegal");
return 1;
}
if(strcmp(chk, "legal") == 1|| strcmp(chk, "ilegal") == 1) return SendClientMessage(playerid,COLOR_ERROR,"usage: /load legal - ilegal");
if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 403 && GetVehicleModel(GetPlayerVehicleID(playerid)) != 514
&& GetVehicleModel(GetPlayerVehicleID(playerid)) != 515) return 1;
if(strcmp(chk, "legal") == 0)){
Crcp[playerid] = 2;
HasTruckLoaded[playerid]=1;
new rand = random(sizeof(RandomTruckPoint));
SetPlayerRaceCheckpoint( playerid, 2,RandomTruckPoint[rand][0],RandomTruckPoint[rand][1],RandomTruckPoint[rand][2], 0, 0, 0 ,2 );
new mrand = 50000 + random(500);
return 1;
}
if(strcmp(chk, "ilegal") == 0)){ // i ilegal
Crcp[playerid] = 2;
HasTruckLoaded[playerid]=1;
new rand = random(sizeof(RandomTruckPoint));
SetPlayerRaceCheckpoint( playerid, 2,RandomTruckPoint[rand][0],RandomTruckPoint[rand][1],RandomTruckPoint[rand][2], 0, 0, 0 ,2 );
new mrand = 100000 + random(1000);
}
return 1;
}
Re: command option problem -
Scenario - 21.07.2013
Fix the indentation and then I'll take a look at the command.
Re: command option problem -
omidi - 21.07.2013
can you look at it now ?
Re: command option problem -
Scenario - 21.07.2013
Try this:
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;
}
Read the comments!
EDIT: Sorry, missed a few things and adjusted accordingly.