SA-MP Forums Archive
Multiple commands for same thing - 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: Multiple commands for same thing (/showthread.php?tid=408056)



Multiple commands for same thing - PDChaseOfficial - 16.01.2013

Hey,

Im creating a vehicle command where player does /v [option]. One of the options is park, and I want to player to be able to type /v park or /v p (which would both do the same thing), but with my code, only park works.

Код:
//This works well:
CMD:vehicle(playerid,params[])
{
	new option[10];
	new vehoption;
	if(sscanf(params,"s[10]",option))


//this works only for park (not p)
if(!strcmp(option,"p",true)||!strcmp(option,"park",true))
do you know whats happening?


Re: Multiple commands for same thing - LarzI - 16.01.2013

- Ignore previous post; I misread -


It doesn't work with OR? It really should unless you've done some funky shit.
Please provide the entire code for the command.


Re: Multiple commands for same thing - PDChaseOfficial - 16.01.2013

I have just other strcmps like buypark, scrap and stuff. all work fine. Can't think of what could make it wrong.


Re: Multiple commands for same thing - LarzI - 16.01.2013

Quote:
Originally Posted by PDChaseOfficial
Посмотреть сообщение
I have just other strcmps like buypark, scrap and stuff. all work fine. Can't think of what could make it wrong.
Neither can we, unless you provide all the associated code.


Re: Multiple commands for same thing - Threshold - 16.01.2013

You said when you are trying to do '/v p', it will not work. Are you sure you haven't posted the wrong command, this shows your /vehicle command, unless you have return cmd_vehicle(playerid, params); under your /v command. :S

Just a guess.


Re: Multiple commands for same thing - PDChaseOfficial - 16.01.2013

Here's all of the cmd:vehicle code. I tried to write it as neat as possible.

Код:
CMD:vehicle(playerid,params[])
{
	new option[10];
	new vehoption;
	if(sscanf(params,"s[10]",option))
	{
		SendClientMessage(playerid,COLOR_YELLOW,"-------------------------Vehicle System-------------------------");
		SendClientMessage(playerid,COLOR_YELLOW,"/v [option]->g(et),buy,sell,park,buypark,scrap");
		SendClientMessage(playerid,COLOR_YELLOW,"--------------------------------------------------------------------------");
	}
	if(strlen(option)<3) return 1;
	if(!strcmp(option,"list",true))
	{
	    if(PlayerInfo[playerid][pVeh1]==0&&PlayerInfo[playerid][pVeh2]==0&&PlayerInfo[playerid][pVeh3]==0) return SendClientMessage(playerid,COLOR_YELLOW,"You do not have any vehicles.");
	    new list[80];
	    if(PlayerInfo[playerid][pVeh1]!=0) format(list,sizeof(list),"Vehicle 1 (%s): Plate: %s.",GetModelFriendlyName(VehicleInfo[PlayerInfo[playerid][pVeh1]][Model]),VehicleInfo[PlayerInfo[playerid][pVeh1]][Plate]);
	    if(PlayerInfo[playerid][pVeh2]!=0) format(list,sizeof(list),"Vehicle 2 (%s): Plate: %s.",GetModelFriendlyName(VehicleInfo[PlayerInfo[playerid][pVeh2]][Model]),VehicleInfo[PlayerInfo[playerid][pVeh2]][Plate]);
	    if(PlayerInfo[playerid][pVeh3]!=0) format(list,sizeof(list),"Vehicle 3 (%s): Plate: %s.",GetModelFriendlyName(VehicleInfo[PlayerInfo[playerid][pVeh3]][Model]),VehicleInfo[PlayerInfo[playerid][pVeh3]][Plate]);
	    SendClientMessage(playerid,COLOR_YELLOW,list);
	    return 1;
	}
	if(!strcmp(option,"buy",true))
	{
	    if(!IsPlayerInRangeOfPoint(playerid,15,pos_dealership_commerce)&&!IsPlayerInRangeOfPoint(playerid,15,pos_dealership_grotti)) return SendClientMessage(playerid,COLOR_RED,"You have to be at a vehicle dealership to use this.");
		return ShowPlayerDialog(playerid,DIALOG_VEH_CATEGORY,DIALOG_STYLE_LIST,"Buy Vehicle (Category)","Offroad\nSports\nCasual\n2 Wheel\nVans","Choose","Exit");
	}
	if(!strcmp(option,"scrap",true))
	{
		if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,COLOR_RED,"You have to be in your vehicle to use this.");
	    if(GetPlayerVehicleID(playerid)!=VehicleInfo[PlayerInfo[playerid][pVeh1]][gID]&&GetPlayerVehicleID(playerid)!=VehicleInfo[PlayerInfo[playerid][pVeh2]][gID]&&GetPlayerVehicleID(playerid)!=VehicleInfo[PlayerInfo[playerid][pVeh3]][gID]&&GetPlayerVehicleID(playerid)==0) return SendClientMessage(playerid,COLOR_RED,"You have to be in your vehicle to use this.");
	    if(GetPlayerVehicleID(playerid)==VehicleInfo[PlayerInfo[playerid][pVeh1]][gID])
	    {
			GivePlayerCash(playerid,GetModelPrice(VehicleInfo[PlayerInfo[playerid][pVeh1]][Model])/2);
	        new sellstring[100];
	        format(sellstring,sizeof(sellstring),"You scrapped your vehicle for $%i.",GetModelPrice(VehicleInfo[PlayerInfo[playerid][pVeh1]][Model])/2);
	        SendClientMessage(playerid,COLOR_YELLOW,sellstring);
			DestroyVehicle(GetPlayerVehicleID(playerid));
			new query[80];
		    format(query,sizeof(query),"DELETE FROM Vehicles WHERE ID = %i",PlayerInfo[playerid][pVeh1]);
		    mysql_query(query);
		    LoadVehicleStats(PlayerInfo[playerid][pVeh1]);
		    ResetVehicleStats(PlayerInfo[playerid][pVeh1]);
		    PlayerInfo[playerid][pVeh1]=0;
		    return 1;
	    }
	    if(GetPlayerVehicleID(playerid)==VehicleInfo[PlayerInfo[playerid][pVeh2]][gID])
	    {
			GivePlayerCash(playerid,GetModelPrice(VehicleInfo[PlayerInfo[playerid][pVeh2]][Model])/2);
	        new sellstring[100];
	        format(sellstring,sizeof(sellstring),"You scrapped your vehicle for $%i.",GetModelPrice(VehicleInfo[PlayerInfo[playerid][pVeh2]][Model])/2);
	        SendClientMessage(playerid,COLOR_YELLOW,sellstring);
			DestroyVehicle(GetPlayerVehicleID(playerid));
			new query[80];
		    format(query,sizeof(query),"DELETE FROM Vehicles WHERE ID = %i",PlayerInfo[playerid][pVeh2]);
		    mysql_query(query);
		    LoadVehicleStats(PlayerInfo[playerid][pVeh2]);
		    ResetVehicleStats(PlayerInfo[playerid][pVeh2]);
			PlayerInfo[playerid][pVeh2]=0;
			return 1;
	    }
	    if(GetPlayerVehicleID(playerid)==VehicleInfo[PlayerInfo[playerid][pVeh3]][gID])
	    {
			GivePlayerCash(playerid,GetModelPrice(VehicleInfo[PlayerInfo[playerid][pVeh3]][Model])/2);
	        new sellstring[100];
	        format(sellstring,sizeof(sellstring),"You scrapped your vehicle for $%i.",GetModelPrice(VehicleInfo[PlayerInfo[playerid][pVeh3]][Model])/2);
	        SendClientMessage(playerid,COLOR_YELLOW,sellstring);
			DestroyVehicle(GetPlayerVehicleID(playerid));
			new query[80];
		    format(query,sizeof(query),"DELETE FROM Vehicles WHERE ID = %i",PlayerInfo[playerid][pVeh3]);
		    mysql_query(query);
		    ResetVehicleStats(PlayerInfo[playerid][pVeh3]);
			PlayerInfo[playerid][pVeh3]=0;
			return 1;
	    }
	}
	if(!strcmp(option,"buypark",true))
	{
	    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,COLOR_RED,"You have to be in your vehicle to use this.");
	    if(GetPlayerVehicleID(playerid)!=VehicleInfo[PlayerInfo[playerid][pVeh1]][gID]&&GetPlayerVehicleID(playerid)!=VehicleInfo[PlayerInfo[playerid][pVeh2]][gID]&&GetPlayerVehicleID(playerid)!=VehicleInfo[PlayerInfo[playerid][pVeh3]][gID]&&GetPlayerVehicleID(playerid)==0) return SendClientMessage(playerid,COLOR_RED,"You have to be in your vehicle to use this.");
	    if(GetPlayerVehicleID(playerid)==VehicleInfo[PlayerInfo[playerid][pVeh1]][gID])
	    {
	        if(PlayerInfo[playerid][pCash]<1500) return SendClientMessage(playerid,COLOR_RED,"Changing your parking place costs $1500.");
	        new Float:x,Float:y,Float:z,Float:angle;
	        GetVehicleZAngle(GetPlayerVehicleID(playerid),angle);
	        GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
	        VehicleInfo[PlayerInfo[playerid][pVeh1]][Parkx]=x;
	        VehicleInfo[PlayerInfo[playerid][pVeh1]][Parky]=y;
	        VehicleInfo[PlayerInfo[playerid][pVeh1]][Parkz]=z;
	        VehicleInfo[PlayerInfo[playerid][pVeh1]][Parkangle]=angle;
	        new query[150];
	        format(query,sizeof(query),"UPDATE Vehicles SET Parkx = '%f', Parky = '%f' Parkz = '%f' Parkangle = '%f' WHERE ID = %i",x,y,z,angle,PlayerInfo[playerid][pVeh1]);
	        mysql_query(query);
			GivePlayerCash(playerid,-1500);
			SendClientMessage(playerid,COLOR_YELLOW,"You bought a new parking place for $1500.");
			return 1;
	    }
	    if(GetPlayerVehicleID(playerid)==VehicleInfo[PlayerInfo[playerid][pVeh2]][gID])
	    {
	        if(PlayerInfo[playerid][pCash]<1500) return SendClientMessage(playerid,COLOR_RED,"Changing your parking place costs $1500.");
	        new Float:x,Float:y,Float:z,Float:angle;
	        GetVehicleZAngle(GetPlayerVehicleID(playerid),angle);
	        GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
	        VehicleInfo[PlayerInfo[playerid][pVeh2]][Parkx]=x;
	        VehicleInfo[PlayerInfo[playerid][pVeh2]][Parky]=y;
	        VehicleInfo[PlayerInfo[playerid][pVeh2]][Parkz]=z;
	        VehicleInfo[PlayerInfo[playerid][pVeh2]][Parkangle]=angle;
	        new query[80];
	        format(query,sizeof(query),"UPDATE Vehicles SET Parkx = '%f', Parky = '%f', Parkz = '%f', Parkangle = '%f' WHERE ID = %i",x,y,z,angle,PlayerInfo[playerid][pVeh2]);
	        mysql_query(query);
			GivePlayerCash(playerid,-1500);
			SendClientMessage(playerid,COLOR_YELLOW,"You bought a new parking place for $1500.");
			return 1;
	    }
	    if(GetPlayerVehicleID(playerid)==VehicleInfo[PlayerInfo[playerid][pVeh3]][gID])
	    {
	        if(PlayerInfo[playerid][pCash]<1500) return SendClientMessage(playerid,COLOR_RED,"Changing your parking place costs $1500.");
	        new Float:x,Float:y,Float:z,Float:angle;
	        GetVehicleZAngle(GetPlayerVehicleID(playerid),angle);
	        GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
	        VehicleInfo[PlayerInfo[playerid][pVeh3]][Parkx]=x;
	        VehicleInfo[PlayerInfo[playerid][pVeh3]][Parky]=y;
	        VehicleInfo[PlayerInfo[playerid][pVeh3]][Parkz]=z;
	        VehicleInfo[PlayerInfo[playerid][pVeh3]][Parkangle]=angle;
	        new query[80];
	        format(query,sizeof(query),"UPDATE Vehicles SET Parkx = '%f', Parky = '%f', Parkz = '%f', Parkangle = '%f' WHERE ID = %i",x,y,z,angle,PlayerInfo[playerid][pVeh3]);
	        mysql_query(query);
			GivePlayerCash(playerid,-1500);
			SendClientMessage(playerid,COLOR_YELLOW,"You bought a new parking place for $1500.");
			return 1;
	    }
	}
	if(!strcmp(option,"p",true)||!strcmp(option,"park",true))
 	{
	    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,COLOR_RED,"You have to be in your vehicle to use this.");
	    if(GetPlayerVehicleID(playerid)!=VehicleInfo[PlayerInfo[playerid][pVeh1]][gID]&&GetPlayerVehicleID(playerid)!=VehicleInfo[PlayerInfo[playerid][pVeh2]][gID]&&GetPlayerVehicleID(playerid)!=VehicleInfo[PlayerInfo[playerid][pVeh3]][gID]&&GetPlayerVehicleID(playerid)==0) return SendClientMessage(playerid,COLOR_RED,"You have to be in your vehicle to use this.");
	    if(GetPlayerVehicleID(playerid)==VehicleInfo[PlayerInfo[playerid][pVeh1]][gID])
	    {
	        if(!IsPlayerInRangeOfPoint(playerid,5,VehicleInfo[PlayerInfo[playerid][pVeh1]][Parkx],VehicleInfo[PlayerInfo[playerid][pVeh1]][Parky],VehicleInfo[PlayerInfo[playerid][pVeh1]][Parkz]))
			{
			    SetPlayerCheckpoint(playerid,VehicleInfo[PlayerInfo[playerid][pVeh1]][Parkx],VehicleInfo[PlayerInfo[playerid][pVeh1]][Parky],VehicleInfo[PlayerInfo[playerid][pVeh1]][Parkz],4);
				return SendClientMessage(playerid,COLOR_RED,"You have to be at your parking point to park your vehicle.");
			}
	        DestroyVehicle(VehicleInfo[PlayerInfo[playerid][pVeh1]][gID]);
	        VehicleInfo[PlayerInfo[playerid][pVeh1]][gID]=-1;
	        VehicleInfo[PlayerInfo[playerid][pVeh1]][Spawned]=0;
	    }
	    if(GetPlayerVehicleID(playerid)==VehicleInfo[PlayerInfo[playerid][pVeh2]][gID])
	    {
	        if(!IsPlayerInRangeOfPoint(playerid,5,VehicleInfo[PlayerInfo[playerid][pVeh2]][Parkx],VehicleInfo[PlayerInfo[playerid][pVeh2]][Parky],VehicleInfo[PlayerInfo[playerid][pVeh2]][Parkz]))
			{
			    SetPlayerCheckpoint(playerid,4,VehicleInfo[PlayerInfo[playerid][pVeh2]][Parkx],VehicleInfo[PlayerInfo[playerid][pVeh2]][Parky],VehicleInfo[PlayerInfo[playerid][pVeh2]][Parkz]);
				return SendClientMessage(playerid,COLOR_RED,"You have to be at your parking point to park your vehicle.");
			}
	        DestroyVehicle(VehicleInfo[PlayerInfo[playerid][pVeh2]][gID]);
	        VehicleInfo[PlayerInfo[playerid][pVeh2]][gID]=-1;
	        VehicleInfo[PlayerInfo[playerid][pVeh1]][Spawned]=0;
	    }
	    if(GetPlayerVehicleID(playerid)==VehicleInfo[PlayerInfo[playerid][pVeh3]][gID])
	    {
	        if(!IsPlayerInRangeOfPoint(playerid,5,VehicleInfo[PlayerInfo[playerid][pVeh3]][Parkx],VehicleInfo[PlayerInfo[playerid][pVeh3]][Parky],VehicleInfo[PlayerInfo[playerid][pVeh3]][Parkz]))
			{
			    SetPlayerCheckpoint(playerid,4,VehicleInfo[PlayerInfo[playerid][pVeh3]][Parkx],VehicleInfo[PlayerInfo[playerid][pVeh3]][Parky],VehicleInfo[PlayerInfo[playerid][pVeh3]][Parkz]);
				return SendClientMessage(playerid,COLOR_RED,"You have to be at your parking point to park your vehicle.");
			}
	        DestroyVehicle(VehicleInfo[PlayerInfo[playerid][pVeh3]][gID]);
	        VehicleInfo[PlayerInfo[playerid][pVeh3]][gID]=-1;
	        VehicleInfo[PlayerInfo[playerid][pVeh1]][Spawned]=0;
	    }
	    return SendClientMessage(playerid,COLOR_GREEN,"Vehicle parked.");
	}
	sscanf(params,"s[10]i",option,vehoption);
	if(!strcmp(option,"get",true))
	{
	    if(VehicleInfo[PlayerInfo[playerid][pVeh1]][Spawned]==1||VehicleInfo[PlayerInfo[playerid][pVeh2]][Spawned]==1||VehicleInfo[PlayerInfo[playerid][pVeh3]][Spawned]==1) return SendClientMessage(playerid,COLOR_RED,"You already have your vehicle spawned. Park it first.");
	    if(vehoption<1||vehoption>3) return SendClientMessage(playerid,COLOR_RED,"/v get [slot(1-3)]");
	    if(PlayerInfo[playerid][pVeh1]==0&&PlayerInfo[playerid][pVeh2]==0&&PlayerInfo[playerid][pVeh3]==0) return SendClientMessage(playerid,COLOR_RED,"You don't have a vehicle to spawn.");
	    if(vehoption==1)
		{
		    if(PlayerInfo[playerid][pVeh1]==0) return SendClientMessage(playerid,COLOR_RED,"You don't own vehicle on this slot.");
			SetVehicleNumberPlate(VehicleInfo[PlayerInfo[playerid][pVeh1]][gID]=CreateVehicle(VehicleInfo[PlayerInfo[playerid][pVeh1]][Model],VehicleInfo[PlayerInfo[playerid][pVeh1]][Parkx],VehicleInfo[PlayerInfo[playerid][pVeh1]][Parky],VehicleInfo[PlayerInfo[playerid][pVeh1]][Parkz],VehicleInfo[PlayerInfo[playerid][pVeh1]][Parkangle],VehicleInfo[PlayerInfo[playerid][pVeh1]][Col1],VehicleInfo[PlayerInfo[playerid][pVeh1]][Col2],9999999),VehicleInfo[PlayerInfo[playerid][pVeh1]][Plate]);
			VehicleInfo[PlayerInfo[playerid][pVeh1]][Spawned]=1;
		}
		if(vehoption==2)
		{
		    if(PlayerInfo[playerid][pVeh2]==0) return SendClientMessage(playerid,COLOR_RED,"You don't own vehicle on this slot.");
			if(!IsValidRealVehicleID(PlayerInfo[playerid][pVeh2])) return SendClientMessage(playerid,COLOR_RED,"ERROR:Invalid Vehicle.");
			SetVehicleNumberPlate(VehicleInfo[PlayerInfo[playerid][pVeh2]][gID]=CreateVehicle(VehicleInfo[PlayerInfo[playerid][pVeh2]][Model],VehicleInfo[PlayerInfo[playerid][pVeh2]][Parkx],VehicleInfo[PlayerInfo[playerid][pVeh2]][Parky],VehicleInfo[PlayerInfo[playerid][pVeh2]][Parkz],VehicleInfo[PlayerInfo[playerid][pVeh2]][Parkangle],VehicleInfo[PlayerInfo[playerid][pVeh2]][Col1],VehicleInfo[PlayerInfo[playerid][pVeh2]][Col2],9999999),VehicleInfo[PlayerInfo[playerid][pVeh2]][Plate]);
			VehicleInfo[PlayerInfo[playerid][pVeh1]][Spawned]=1;
		}
		if(vehoption==3)
		{
		    if(PlayerInfo[playerid][pVeh3]==0) return SendClientMessage(playerid,COLOR_RED,"You don't own vehicle on this slot.");
			if(!IsValidRealVehicleID(PlayerInfo[playerid][pVeh3])) return SendClientMessage(playerid,COLOR_RED,"ERROR:Invalid Vehicle.");
			SetVehicleNumberPlate(VehicleInfo[PlayerInfo[playerid][pVeh3]][gID]=CreateVehicle(VehicleInfo[PlayerInfo[playerid][pVeh3]][Model],VehicleInfo[PlayerInfo[playerid][pVeh3]][Parkx],VehicleInfo[PlayerInfo[playerid][pVeh3]][Parky],VehicleInfo[PlayerInfo[playerid][pVeh3]][Parkz],VehicleInfo[PlayerInfo[playerid][pVeh3]][Parkangle],VehicleInfo[PlayerInfo[playerid][pVeh3]][Col1],VehicleInfo[PlayerInfo[playerid][pVeh3]][Col2],9999999),VehicleInfo[PlayerInfo[playerid][pVeh3]][Plate]);
			VehicleInfo[PlayerInfo[playerid][pVeh1]][Spawned]=1;
		}
		return SendClientMessage(playerid,COLOR_GREEN,"Vehicle spawned.");
	}
	return 1;
}



Re: Multiple commands for same thing - SuperViper - 16.01.2013

pawn Код:
if(strlen(option)<3) return 1;
p is obviously less than 3 characters, which is why it won't work. Just remove that line completely.


Re: Multiple commands for same thing - Threshold - 16.01.2013

Oh man, didn't even realise you posted the code... but yeah, Viper is right xD