SA-MP Forums Archive
Name based command - 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: Name based command (/showthread.php?tid=96542)



Name based command - Ov3rl0rd - 09.09.2009

Alright, I haven't really seen anything like this code so I don't know exactly what I am doing wrong. Now here is my code

Код:
	new playername[MAX_PLAYER_NAME];
	if (strcmp("/change", cmdtext, true, 10) == 0)
	{
		GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
		if(strcmp("Player_Name",playername, true, 10) == 0)
		{
 			SetPlayerSkin(playerid, 187);
			return 1;
 		}
		else
		{
			SendClientMessage(playerid, 0xBFC0C2FF, "Can not use this command");
  		return 1;
 	  }
	}
Now that code works. It allows only the player with that name to use that command.

However I have a issue. If I try
Код:
		if (strcmp("/change", cmdtext, true, 10) == 0)
	{
		GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
		if(strcmp("Player_Name",playername, true, 10) == 0)
		{
 			SetPlayerSkin(playerid, 187);
			return 1;
 		}
 		else if strcmp("Player_Two",playername, true, 10) == 0)
		{
 			SetPlayerSkin(playerid, 187);
			return 1;
 		}
		else
		{
			SendClientMessage(playerid, 0xBFC0C2FF, "Can not use this command");
  		return 1;
 	  }
	}
It gives me errors. Or even if I make a whole new command like this
Код:
	if (strcmp("/clothes", cmdtext, true, 10) == 0)
	{
  	GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
		if(strcmp("Player_Two",playername, true, 5) == 0)
		{
 			SetPlayerSkin(playerid, 186);
 			return 1;
  	}
		else
		{
			SendClientMessage(playerid, 0xBFC0C2FF, "Can not use this command");
			return 1;
 	  }
	}
it wont work. So basically only the first command works. Any idea why?


Re: Name based command - Abernethy - 09.09.2009

pawn Код:
else
        {
            SendClientMessage(playerid, 0xBFC0C2FF, "Can not use this command");
            return 1;
Post your errors.
Is it possible your forgot the closing brace?


Re: Name based command - Ov3rl0rd - 09.09.2009

Errors and warnings for the second code.
The 3rd code executes but it wont work in game. I just get Server Unknown command

Код:
C:\Documents and Settings\dad\My Documents\samp02Xserver.win32\filterscripts\Surveliance.pwn(88) : error 001: expected token: "*then", but found ")"
C:\Documents and Settings\dad\My Documents\samp02Xserver.win32\filterscripts\Surveliance.pwn(88) : error 029: invalid expression, assumed zero
C:\Documents and Settings\dad\My Documents\samp02Xserver.win32\filterscripts\Surveliance.pwn(93) : warning 225: unreachable code
C:\Documents and Settings\dad\My Documents\samp02Xserver.win32\filterscripts\Surveliance.pwn(93) : error 029: invalid expression, assumed zero



Re: Name based command - Abernethy - 09.09.2009

Meh, it's pissing me off too.
Why don't you use if (GetPlayerName(playerid, name, sizeof(name) == Player_One) or something.


Re: Name based command - Ov3rl0rd - 09.09.2009

nvm I got it xD

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	new playername[MAX_PLAYER_NAME];
	if (strcmp("/clothes", cmdtext, true, 10) == 0)
	{
  	GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
		if(strcmp("Player_Name",playername, true, 5) == 0)
		{
 			SetPlayerSkin(playerid, 186);
 			return 1;
  	}
		else if(strcmp("Player_Two",playername, true, 10) == 0)
		{
 			SetPlayerSkin(playerid, 187);
			return 1;
		}
		else
		{
			SendClientMessage(playerid, 0xBFC0C2FF, "Can not use this command");
			return 1;
 		}
	}
	return 0;
}
Don't know what was wrong but it works now xD