[HELP] Creating optional command parameters
#1

Код:
CMD:car(playerid,params[])
{
	new string[128],cID,cID2,vID;
	new Float:x,Float:y,Float:z;
    if(PInfo[playerid][Level] < 1)
    return SendClientMessage(playerid,STEALTH_BLUE,"You need to be level 2 to use this command.");
	if(sscanf(params,"dzz",vID,cID,cID2))
	return SendClientMessage(playerid,COLOR_INDIANRED,"USAGE /car [NAME] Optional: [COLOR1] [COLOR2]");
	if(vCar[playerid] != -1)
		{
 			DestroyVehicle(vCar[playerid]);
		}
	CMDMessageToAdmins(playerid,"CAR");
	GetPlayerPos(playerid,x,y,z);
	vCar[playerid] = CreateVehicle(vID,x+2,y,z,0,cID,cID2,0);
	PutPlayerInVehicle(playerid,vCar[playerid], 0);
	LinkVehicleToInterior(vCar[playerid], GetPlayerInterior(playerid));
	format(string,sizeof(string),"You have spawned vehicle %d with color %d and %d.",vID,cID,cID2);
	SendClientMessage(playerid,COLOR_GREENYELLOW,string);
    return 1;
}
How do i create optional parameters for cID and cID2
Reply
#2

I think this code would work
Код:
if(!sscanf(params, "ddd", vID, cID,cID2))
{
	 //code here if player write the optional color
}
else if(!sscanf(params, "d", vID))
{
	//same code here with random colours
}
else return SendClientMessage(playerid, COLOR_GREENYELLOW, "USAGE: /car [modelid] [colour1 optional] [colour2 optional]");
Reply
#3

@bondowocopz: Really? Don't ever post untested commands/codes. It's not optional in your code.
The proper code would be:
pawn Код:
CMD:car(playerid,params[])
{
    new string[128],cID,cID2,vID;
    new Float:x,Float:y,Float:z;
    if(PInfo[playerid][Level] < 1)
    return SendClientMessage(playerid,STEALTH_BLUE,"You need to be level 2 to use this command.");
    if(sscanf(params,"dI(0)I(0)",vID,cID,cID2))
    return SendClientMessage(playerid,COLOR_INDIANRED,"USAGE /car [NAME] Optional: [COLOR1] [COLOR2]");
    if(vCar[playerid] != -1)
        {
            DestroyVehicle(vCar[playerid]);
        }
    CMDMessageToAdmins(playerid,"CAR");
    GetPlayerPos(playerid,x,y,z);
    vCar[playerid] = CreateVehicle(vID,x+2,y,z,0,cID,cID2,0);
    PutPlayerInVehicle(playerid,vCar[playerid], 0);
    LinkVehicleToInterior(vCar[playerid], GetPlayerInterior(playerid));
    format(string,sizeof(string),"You have spawned vehicle %d with color %d and %d.",vID,cID,cID2);
    SendClientMessage(playerid,COLOR_GREENYELLOW,string);
        return 1;
}
INFO:
pawn Код:
if(sscanf(params,"dI(0)I(0)",vID,cID,cID2))
I(0) - If nothing has been entered by the user, it chooses 0 as the color. You can change that (0) to any vehicle color value.
Reply
#4

omg i tried that before but i forgot to change color 0 0 in createvehicle to cID and cID2 lol

anyways ty for your help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)