Parameters within parameters
#1

So, the problem is the /aveh create, or remove is just not working. If I type /aveh create I got back the sscanf line but if I fill the parameters nothing happens. Wheres the issue? Im confused.

PHP код:
CMD:aveh(playeridparams[]) {
  new 
parameter[20];
  if(
pData[playerid][p_admin] < 5) return EmTag(playeridYOU_HAVE_NO_PERMISSION);
  if(
sscanf(params"s[20]"parameter)) return UsageTag(playerid"/aveh [CREATE/REMOVE]");
  if(!
strcmp(parameter"create"true)) {
    new 
id = -1midvcolor1vcolor2;
    new 
Float:xFloat:yFloat:zFloat:ang;
    new 
string[128];
    if(
sscanf(params"iii"midvcolor1vcolor2)) return UsageTag(playerid"/aveh create [MODEL] [COLOR1] [COLOR2]");
    if(!(
<= vcolor1 <= 255)) return EmTag(playerid"The specified color1 is invalid (1-255)!");
    if(!(
<= vcolor2 <= 255)) return EmTag(playerid"The specified color2 is invalid (1-255)!");
    if(!(
400 <= mid <= 611)) return EmTag(playerid"The specified model ID is invalid (400-611)!");
    
    
GetPlayerPos(playeridFloat:xFloat:yFloat:z);
    
GetPlayerFacingAngle(playeridFloat:ang);
    
id Vehicle_Create(0midxyzangvcolor1vcolor2);
    if(
id == -1) return EmTag(playerid"The server has reached the limit for dynamic vehicles.");
    
PutPlayerInVehicle(playeridid0);
    return 
1;
  }
  if(!
strcmp(parameter"remove"true)) {
    static 
id 0;
    if(
sscanf(params"d"id)) return UsageTag(playerid"/aveh remove [ID]");
    if(!
IsValidVehicle(id) || Vehicle_GetID(id) == -1) return EmTag(playerid"You have specified an invalid vehicle ID.");
    if (
IsPlayerInAnyVehicle(playerid))
    
    
id GetPlayerVehicleID(playerid);
    
Vehicle_Delete(Vehicle_GetID(id));
    return 
1;
  }
  return 
1;

Reply
#2

Your sscanf is looking for mid, vcolor1, vcolor2 in "params" but there is also "create" word inside, so it is returning 0. You have to use two variables.

Код:
new parameter[20], rest[20];
	
if( sscanf(params, "s[20]S()[20]", parameter, rest) ) return UsageTag(playerid, "/aveh [CREATE/REMOVE]");
Код:
if( !strcmp(parameter, "create") )
		{
			if(sscanf(rest, "ddd", mid, vcolor1, vcolor2)) return UsageTag(playerid, "/aveh create [MODEL] [COLOR1] [COLOR2]");
I've used "ddd" instead of "iii" here, but don't really know what's the difference between these two.
Reply
#3

Quote:
Originally Posted by raydx
Посмотреть сообщение
Your sscanf is looking for mid, vcolor1, vcolor2 in "params" but there is also "create" word inside, so it is returning 0. You have to use two variables.

Код:
new parameter[20], rest[20];
	
if( sscanf(params, "s[20]S()[20]", parameter, rest) ) return UsageTag(playerid, "/aveh [CREATE/REMOVE]");
Код:
if( !strcmp(parameter, "create") )
		{
			if(sscanf(rest, "ddd", mid, vcolor1, vcolor2)) return UsageTag(playerid, "/aveh create [MODEL] [COLOR1] [COLOR2]");
I've used "ddd" instead of "iii" here, but don't really know what's the difference between these two.
Worked perfectly. Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)