Name based command
#1

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?
Reply
#2

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

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
Reply
#4

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)