-
Оптимизация
Ку всем, можно ли как нибудь этот вариант улучшить в качестве кода:
PHP код:
new Float: health, hour, string_eat[11];
GetPlayerHealth(playerid, health);
gettime( hour, _, _ );
if(health >= 100) return SendClientMessage(playerid, -1, "Ты сыт");
if(pInfo[playerid][pLevel] > 3) return SendClientMessage(playerid, -1, "Вы не новечок" );
SetPlayerHealth(playerid, health + 30);
switch(hour)
{
case 7 .. 11: strcat(string_eat, "завтракает");
case 12 .. 16: strcat(string_eat, "обедает");
case 17 .. 21: strcat(string_eat, "ужинает");
default: strcat(string_eat, "кушает");
}
SetPlayerChatBubble(playerid, string_eat, 0xE3B1E1AA, 30, 5000);
ApplyAnimation(playerid, "FOOD", "EAT_Burger", 4.1, 0, 1, 1, 0, 1);
return 1;
-
Не могу назвать себя оптимизатором, но вот мой вариант.
Сделал код более приятным (возможно усложнил НУ ЯЖ ни аптимизатор).
PHP код:
// В самый вверх мода, константы.
#define COLOR_PURPLE ( 0xE3B1E1AA )
const
Float: EAT_LEVEL_UP = 30.0;
// Участок Вашего кода.
// Для удобства.
#define level pInfo[playerid][pLevel]
new
Float: health,
_: hour;
GetPlayerHealth( playerid, health );
gettime( hour, _, _ );
if( health >= 100.0 || level > 3 )
return ( level > 3 && health < 100.0 ) ? SendClientMessage( playerid, -1, "Ошибка: Вы уже не новичок." ) : (
( health >= 100.0 && level < 3 ) ? SendClientMessage( playerid, -1, "Ошибка: Вы уже сыты." ) : 1 );
SetPlayerHealth( playerid, health + EAT_LEVEL_UP );
switch( hour )
{
case 7 .. 11: SetPlayerChatBubble( playerid, "завтракает", COLOR_PURPLE, 30, 5000 );
case 12 .. 16: SetPlayerChatBubble( playerid, "обедает", COLOR_PURPLE, 30, 5000 );
case 17 .. 21: SetPlayerChatBubble( playerid, "ужинает", COLOR_PURPLE, 30, 5000 );
default: SetPlayerChatBubble( playerid, "кушает", COLOR_PURPLE, 30, 5000 );
}
ApplyAnimation( playerid, "FOOD", "EAT_Burger", 4.1, 0, 1, 1, 0, 1 );
#undef level
return 1;
-