SA-MP Forums Archive
What's the problem with this script? - 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: What's the problem with this script? (/showthread.php?tid=68605)



What's the problem with this script? - Jonesycool - 11.03.2009

Hey guys,
I'm a complete scripting noob, and havn't yet committed the time to reading the wiki.
Anyway, what am I doing wrong in this section of the script, I'm trying to create a teleport...

135) : error 001: expected token: "*then", but found "-identifier-"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	new string[256];
	new playermoney;
	new sendername[MAX_PLAYER_NAME];
	new giveplayer[MAX_PLAYER_NAME];
	new cmd[256];
	new giveplayerid, moneys, idx;
	

	cmd = strtok(cmdtext, idx);
{
  if strcmp(cmd,"/teleport",true)
 SetPlayerPos(playerid,-1934.1923,86.2600,25.8087);
  }


	if(strcmp(cmd, "/help", true) == 0) {
		SendPlayerFormattedText(playerid,"Welcome to my server: the server is currently under construction, sorry.",0);
		return 1;
	}
	if(strcmp(cmd, "/objective", true) == 0) {
		SendPlayerFormattedText(playerid,"This section is currently under construction, sorry.",0);
		return 1;
	}
	
 	if(strcmp(cmd, "/givecash", true) == 0) {
	  new tmp[256];
		tmp = strtok(cmdtext, idx);

		if(!strlen(tmp)) {
			SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecash [playerid] [amount]");
			return 1;
		}
		giveplayerid = strval(tmp);

		tmp = strtok(cmdtext, idx);
		if(!strlen(tmp)) {
			SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecash [playerid] [amount]");
			return 1;
		}
 		moneys = strval(tmp);

		//printf("givecash_command: %d %d",giveplayerid,moneys);


		if (IsPlayerConnected(giveplayerid)) {
			GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
			GetPlayerName(playerid, sendername, sizeof(sendername));
			playermoney = GetPlayerMoney(playerid);
			if (moneys > 0 && playermoney >= moneys) {
				GivePlayerMoney(playerid, (0 - moneys));
				GivePlayerMoney(giveplayerid, moneys);
				format(string, sizeof(string), "You have sent %s(player: %d), $%d.", giveplayer,giveplayerid, moneys);
				SendClientMessage(playerid, COLOR_YELLOW, string);
				format(string, sizeof(string), "You have recieved $%d from %s(player: %d).", moneys, sendername, playerid);
				SendClientMessage(giveplayerid, COLOR_YELLOW, string);
				printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
			}
			else {
				SendClientMessage(playerid, COLOR_YELLOW, "Invalid transaction amount.");
			}
		}
		else {
				format(string, sizeof(string), "%d is not an active player.", giveplayerid);
				SendClientMessage(playerid, COLOR_YELLOW, string);
			}
		return 1;
	}

	// PROCESS OTHER COMMANDS


	return 0;
}
Specifically, the bit concerned is:

{
if strcmp(cmd,"/teleport",true)
SetPlayerPos(playerid,-1934.1923,86.2600,25.8087);
}



Re: What's the problem with this script? - JaYmE - 11.03.2009

Maybe it is, this:

pawn Код:
if strcmp(cmd,"/teleport",true)
It should be:

pawn Код:
if ( strcmp(cmdtext, "/Teleport", true ) == 0 ) {

}



Re: What's the problem with this script? - Jonesycool - 11.03.2009

That got rid of the erroe, so thanks, but when I type it into the text box in the game, it does not recognise /Teleport as a valid command...?


Re: What's the problem with this script? - [RP]Rav - 11.03.2009

if strcmp(cmd,"/teleport",true) == 0)
return SetPlayerPos(playerid,-1934.1923,86.2600,25.8087);


Re: What's the problem with this script? - Mikep - 11.03.2009

Try indenting, brackets shouldn't be on the same line as functions or if statements.


Re: What's the problem with this script? - Jonesycool - 11.03.2009

Finally sussed it :P
It was as simple as:

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	new string[256];
	new playermoney;
	new sendername[MAX_PLAYER_NAME];
	new giveplayer[MAX_PLAYER_NAME];
	new cmd[256];
	new giveplayerid, moneys, idx;

	

	cmd = strtok(cmdtext, idx);

  

if(strcmp(cmd,"/teleport",true) == 0) {
		SetPlayerPos(playerid,-1934.1923,86.2600,25.8087);
		return 1;
	}
	if(strcmp(cmd, "/help", true) == 0) {
		SendPlayerFormattedText(playerid,"Welcome to my server: the server is currently under construction, sorry.",0);
		return 1;
Anyway, ty for all ur help guys.


Re: What's the problem with this script? - ICECOLDKILLAK8 - 12.03.2009

I didnt know you could script PAWN like VB