PDA

Просмотр полной версии : [Вопрос] Как оптимизировать



Vasya_Pupkin
04.09.2016, 13:28
Всем Добрый день.
У меня вопрос
Как нибудь можно оптимизировать код ниже?
сократить количество строк?

if(weaponid == 0)
{
switch(armour)
{
case 0:
{
switch(bodypart)
{
case 3: SetPlayerHealth(playerid, health - 5); // Torso.
case 4: SetPlayerHealth(playerid, health - 5); // Groin.
case 5: SetPlayerHealth(playerid, health - 5); // Left Arm.
case 6: SetPlayerHealth(playerid, health - 5); // Right Arm.
case 7: SetPlayerHealth(playerid, health - 5); // Left Leg.
case 8: SetPlayerHealth(playerid, health - 5); // Right Leg.
case 9: SetPlayerHealth(playerid, health - 5); // Head.
}
}
default:
{
switch(bodypart)
{
case 3: SetPlayerHealth(playerid, health - 5); // Torso.
case 4: SetPlayerHealth(playerid, health - 5); // Groin.
case 5: SetPlayerHealth(playerid, health - 5); // Left Arm.
case 6: SetPlayerHealth(playerid, health - 5); // Right Arm.
case 7: SetPlayerHealth(playerid, health - 5); // Left Leg.
case 8: SetPlayerHealth(playerid, health - 5); // Right Leg.
case 9: SetPlayerHealth(playerid, health - 5); // Head.
}
}
}
}

Если возможно то покажите на этом примере.

- - - Добавлено - - -


Все разобрался тему можно закрыть .

vovandolg
04.09.2016, 13:34
if(weaponid == 0)
{
if(armour == 0)
{
if(2 < bodypart < 10) SetPlayerHealth(playerid, health - 5);
}
else
{
if(2 < bodypart < 10) SetPlayerHealth(playerid, health - 5);
}
}