Returning wrong if statement.
#1

Hey there i have coded a command were if a player types "/teleport [DESTINATION]" it teleports them to that destination but its always returning the first if statement no matter what you type heres the command :

Код:
CMD:teleport(playerid, params[])
{
	new TeleportLocation[50];
	
	if (sscanf(params, "z", TeleportLocation)) SendClientMessage(playerid, CommandError, "Usage: /teleport [LocationID/Name]");
	else
	{
	  if(strcmp(TeleportLocation, "help",true) || strcmp(TeleportLocation, "00",true))
	  {
			SendClientMessage(playerid, CommandError, ".:: Using /teleport ::.");
			SendClientMessage(playerid, CommandSuccess, "To use the /teleport command you must have the Name/ID of the place you want to teleport to.");
			SendClientMessage(playerid, CommandSuccess, "To obtain a list of destination names and id's type /teleport names.");
		}
		
		else if(strcmp(TeleportLocation, "names", true) || strcmp(TeleportLocation, "01", true))
	  {
			SendClientMessage(playerid, CommandError, ".:: Destination names and ID's ::.");
			SendClientMessage(playerid, CommandSuccess, "SF Airport (Planes) [Name: fly] [ID: 02]");
		}
		
	  else if(strcmp(TeleportLocation, "fly", true) || strcmp(TeleportLocation, "02", true))
	  {
			if(GetPlayerState(playerid) == 2)
			{
				SetVehiclePos(GetPlayerVehicleID(playerid),-1891.1072,-733.9356,347.8068);
			} else SetPlayerPos(playerid, -1891.1072,-733.9356,347.8068);
		}

	}
	return 1;
}
Reply
#2

strcmp will return a '0' when it is correct.
Reply
#3

So if i change the 'true' to 'false' it would return a 1?.
Reply
#4

That didn't help , I changed the 'true' to a 'false' and still ended up with the same outcome.
Reply
#5

Код:
return 0;
}
put this in the end of the code

Reply
#6

Quote:
Originally Posted by yoan103
Код:
return 0;
}
put this in the end of the code

No, Thats just pointless that would do nothing but make the server return unknown command.
Reply
#7

Use "!strcmp" instead of "strcmp".
Reply
#8

pawn Код:
CMD:teleport(playerid, params[])
{
  new teleportlocation[50];
  if(sscanf(params, "s", teleportlocation)) return SendClientMessage(playerid, COLOR, "Usage: /teleport [location]");
  else if(strcmp(teleportlocation, "help") == 0 || strcmp(teleportlocation, "00") == 0)
  {
    // error message
  }
  else if(strcmp(teleportlocation, "names") == 0)
  {
    // and so on
  }  
  return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)