PDA

Просмотр полной версии : [Вопрос] Оптимизация



Vladimir174
23.06.2016, 20:21
Ку всем, можно ли как нибудь этот вариант улучшить в качестве кода:

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;

Found
24.06.2016, 00:44
Не могу назвать себя оптимизатором, но вот мой вариант.

Сделал код более приятным (возможно усложнил НУ ЯЖ ни аптимизатор).



// В самый вверх мода, константы.

#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;

Desulaid
24.06.2016, 01:26
Для извращения можно добавить http://pro-pawn.ru/showthread.php?13706 и http://pro-pawn.ru/showthread.php?13962, но ваш код и так вполне адекватен.