SA-MP Forums Archive
Returning wrong if statement. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Returning wrong if statement. (/showthread.php?tid=130561)



Returning wrong if statement. - Christopher. - 27.02.2010

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;
}



Re: Returning wrong if statement. - Joe Staff - 27.02.2010

strcmp will return a '0' when it is correct.


Re: Returning wrong if statement. - Christopher. - 27.02.2010

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


Re: Returning wrong if statement. - Christopher. - 27.02.2010

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


Re: Returning wrong if statement. - yoan103 - 27.02.2010

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




Re: Returning wrong if statement. - Christopher. - 27.02.2010

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.


Re: Returning wrong if statement. - Double-O-Seven - 27.02.2010

Use "!strcmp" instead of "strcmp".


Re: Returning wrong if statement. - Miguel - 27.02.2010

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;
}