Рекомендованные сообщения



Не найдено.

2 posts in this topic

Можно ли как-то сделать этот код более нормальным? А то мне кажется что написано как-то странно.

Спойлер

 


    case DIALOG_MASK:
	{
		if(response)
		{
			if(Player[playerid][pMaskuse] == 0 || Player[playerid][pMaskuse] == 1)
			{
				switch(listitem)
				{
				case 0:
					{
						foreach(Player,i)
						{
							if(IsPlayerConnected(i))
							{
								ShowPlayerNameTagForPlayer(i,playerid,0);
							}
						}
						if(Player[playerid][pSex] == 1 || Player[playerid][pSex] == 0) SetPlayerSkin(playerid,29);
						else SetPlayerSkin(playerid,93);
						if(Player[playerid][pMaskuse] == 0)
						{
							f(string,"* %s одевает маскировку.",Player[playerid][pName]);
							ProxDetector(15.0,playerid,string,COLOR_PURPLE);
							SetPlayerColor(playerid,0xFFFFFF00);
							Player[playerid][pMaskuse] = 1;
						}
					}
  				case 1:
					{
						foreach(Player,i)
						{
							if(IsPlayerConnected(i))
							{
								ShowPlayerNameTagForPlayer(i,playerid,0);
							}
						}
						if(Player[playerid][pSex] == 1 || Player[playerid][pSex] == 0) SetPlayerSkin(playerid,33);
						else SetPlayerSkin(playerid,93);
						if(Player[playerid][pMaskuse] == 0)
						{
					 		f(string,"* %s одевает маскировку.",Player[playerid][pName]);
					 		ProxDetector(15.0,playerid,string,COLOR_PURPLE);
						  	SetPlayerColor(playerid,0xFFFFFF00);
						   	Player[playerid][pMaskuse] = 1;
						}
					}
				case 2:
					{
						foreach(Player,i)
						{
							if(IsPlayerConnected(i))
							{
								ShowPlayerNameTagForPlayer(i,playerid,0);
							}
						}
						if(Player[playerid][pSex] == 1 || Player[playerid][pSex] == 0) SetPlayerSkin(playerid,101);
						else SetPlayerSkin(playerid,93);
						if(Player[playerid][pMaskuse] == 0)
						{
					 	f(string,"* %s одевает маскировку.",Player[playerid][pName]);
					 	ProxDetector(15.0,playerid,string,COLOR_PURPLE);
				  		SetPlayerColor(playerid,0xFFFFFF00);
			   			Player[playerid][pMaskuse] = 1;
						}
					}
				case 3:
					{
						foreach(Player,i)
						{
							if(IsPlayerConnected(i))
							{
								ShowPlayerNameTagForPlayer(i,playerid,0);
							}
						}
						if(Player[playerid][pSex] == 1 || Player[playerid][pSex] == 0) SetPlayerSkin(playerid,230);
						else SetPlayerSkin(playerid,93);
					 	if(Player[playerid][pMaskuse] == 0)
						{
					 	f(string,"* %s одевает маскировку.",Player[playerid][pName]);
					 	ProxDetector(15.0,playerid,string,COLOR_PURPLE);
					 	SetPlayerColor(playerid,0xFFFFFF00);
					 	Player[playerid][pMaskuse] = 1;
						}
					}
				case 4:
				 	{
						foreach(Player,i)
						{
							if(IsPlayerConnected(i))
							{
								ShowPlayerNameTagForPlayer(i,playerid,0);
							}
						}
						if(Player[playerid][pSex] == 1 || Player[playerid][pSex] == 0) SetPlayerSkin(playerid,93);
						else SetPlayerSkin(playerid,93);
						if(Player[playerid][pMaskuse] == 0)
						{
					 	f(string,"* %s одевает маскировку.",Player[playerid][pName]);
					 	ProxDetector(15.0,playerid,string,COLOR_PURPLE);
					 	SetPlayerColor(playerid,0xFFFFFF00);
					 	Player[playerid][pMaskuse] = 1;
						}
					}
				case 5:
					{
						if(Player[playerid][pMaskuse] == 0)
						{
							switch(Player[playerid][pSex])
							{
							case 1:send(playerid,0xFF0000AA,"[ОШИБКА] {FFFFFF}Ты не одевал маскировку.");
							case 2:send(playerid,0xFF0000AA,"[ОШИБКА] {FFFFFF}Ты не одевала маскировку.");
							}
							return 1;
						}
						foreach(Player,i)
						{
							if(IsPlayerConnected(i))
							{
								ShowPlayerNameTagForPlayer(i,playerid,1);
							}
						}
				 		if(Player[playerid][pMember] == 0) SetPlayerSkin(playerid,Player[playerid][pChar]);
					 	else SetPlayerSkin(playerid,Player[playerid][pChar]);
					 	Player[playerid][pMaskuse] = 0;
						f(string,"* %s снимает маскировку.",Player[playerid][pName]);
						ProxDetector(15.0,playerid,string,COLOR_PURPLE);
						SetPlayerColor(playerid,0xFFFFFF20);
					}
				}
			}
		}
		return 1;
	}

 

 

Edited by odosenok
Причина: занес код под спойлер

Share this post


Link to post
Share on other sites

@kala4ik, можно лишь убрать switch (в приведенных здесь примерах они скорее потеряют в производительности, потому в них нет смысла), поправить табуляцию, создать выход из функции в начале, если response равно нулю, а также убрал внутри foreach проверку на подключение игрока (это не требуется, если перебираете игроков с помощью foreach):

 

Спойлер

case DIALOG_MASK:
{
	if(!response)
		return 1;
	
	if(!(Player[playerid][pMaskuse] == 0 || Player[playerid][pMaskuse] == 1))
		return 1;

	switch(listitem)
	{
		case 0:
		{
			foreach(Player,i)
			{
				ShowPlayerNameTagForPlayer(i,playerid,0);
			}
			
			if(Player[playerid][pSex] == 1 || Player[playerid][pSex] == 0) SetPlayerSkin(playerid,29);
			else SetPlayerSkin(playerid,93);
			
			if(Player[playerid][pMaskuse] == 0)
			{
				f(string,"* %s одевает маскировку.",Player[playerid][pName]);
				ProxDetector(15.0,playerid,string,COLOR_PURPLE);
				SetPlayerColor(playerid,0xFFFFFF00);
				Player[playerid][pMaskuse] = 1;
			}
		}	
		case 1:
		{
			foreach(Player,i)
			{
				ShowPlayerNameTagForPlayer(i,playerid,0);
			}
			
			if(Player[playerid][pSex] == 1 || Player[playerid][pSex] == 0) SetPlayerSkin(playerid,33);
			else SetPlayerSkin(playerid,93);
			
			if(Player[playerid][pMaskuse] == 0)
			{
				f(string,"* %s одевает маскировку.",Player[playerid][pName]);
				ProxDetector(15.0,playerid,string,COLOR_PURPLE);
				SetPlayerColor(playerid,0xFFFFFF00);
				Player[playerid][pMaskuse] = 1;
			}
		}
		case 2:
		{
			foreach(Player,i)
			{
				ShowPlayerNameTagForPlayer(i,playerid,0);
			}
			
			if(Player[playerid][pSex] == 1 || Player[playerid][pSex] == 0) SetPlayerSkin(playerid,101);
			else SetPlayerSkin(playerid,93);
			
			if(Player[playerid][pMaskuse] == 0)
			{
				f(string,"* %s одевает маскировку.",Player[playerid][pName]);
				ProxDetector(15.0,playerid,string,COLOR_PURPLE);
				SetPlayerColor(playerid,0xFFFFFF00);
				Player[playerid][pMaskuse] = 1;
			}
		}
		case 3:
		{
			foreach(Player,i)
			{
				ShowPlayerNameTagForPlayer(i,playerid,0);
			}
			
			if(Player[playerid][pSex] == 1 || Player[playerid][pSex] == 0) SetPlayerSkin(playerid,230);
			else SetPlayerSkin(playerid,93);
			
			if(Player[playerid][pMaskuse] == 0)
			{
				f(string,"* %s одевает маскировку.",Player[playerid][pName]);
				ProxDetector(15.0,playerid,string,COLOR_PURPLE);
				SetPlayerColor(playerid,0xFFFFFF00);
				Player[playerid][pMaskuse] = 1;
			}
		}
		case 4:
		{
			foreach(Player,i)
			{
				ShowPlayerNameTagForPlayer(i,playerid,0);
			}
			
			if(Player[playerid][pSex] == 1 || Player[playerid][pSex] == 0) SetPlayerSkin(playerid,93);
			else SetPlayerSkin(playerid,93);
			
			if(Player[playerid][pMaskuse] == 0)
			{
				f(string,"* %s одевает маскировку.",Player[playerid][pName]);
				ProxDetector(15.0,playerid,string,COLOR_PURPLE);
				SetPlayerColor(playerid,0xFFFFFF00);
				Player[playerid][pMaskuse] = 1;
			}
		}
		case 5:
		{
			if(Player[playerid][pMaskuse] == 0)
			{
				new sex = Player[playerid][pSex];
				
				if(sex == 1)
					send(playerid,0xFF0000AA,"[ОШИБКА] {FFFFFF}Ты не одевал маскировку.");
				else
					send(playerid,0xFF0000AA,"[ОШИБКА] {FFFFFF}Ты не одевала маскировку.");

				return 1;
			}
			
			foreach(Player,i)
			{
				ShowPlayerNameTagForPlayer(i,playerid,1);
			}
			
			if(Player[playerid][pMember] == 0) SetPlayerSkin(playerid,Player[playerid][pChar]);
			else SetPlayerSkin(playerid,Player[playerid][pChar]);
			
			Player[playerid][pMaskuse] = 0;
			f(string,"* %s снимает маскировку.",Player[playerid][pName]);
			ProxDetector(15.0,playerid,string,COLOR_PURPLE);
			SetPlayerColor(playerid,0xFFFFFF20);
		}
	}
	return 1;
}

 

 

Если хотите менее раздутый код в OnDialogResponse, воспользуйтесь диалоговыми процессорами.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • warrion4ik
      By warrion4ik
      При телепорте по метке она тепает под текстуры и приходится перетелепортироваться, как это можно исправить?
      Видео: https://youtu.be/FLjer8lfGc0