23.09.2010, 15:34
@Luka P.:
Nice but the your code will work slower than a switch-case statement. To be honest, the code below works 2 times faster than your code.
Hope you don't mind.
Oh, and if you say, it's too long.. Well here, all in one line. But that's ugly.. Though still it shorter.
Nice but the your code will work slower than a switch-case statement. To be honest, the code below works 2 times faster than your code.
Hope you don't mind.
pawn Код:
stock returnWeaponSlot(weaponid)
{
switch(weaponid)
{
case 0..1: return 0;
case 2..9: return 1;
case 22..24: return 2;
case 25..27: return 3;
case 28..29: return 4;
case 30..31: return 5;
case 33..34: return 6;
case 35..38: return 7;
case 16..18, 39: return 8;
case 41..43: return 9;
case 11..15: return 10;
case 44..46: return 11;
case 40: return 12;
}
return -1;
}
pawn Код:
stock returnWeaponSlot(weaponid) { switch(weaponid) { case 0..1: return 0; case 2..9: return 1; case 22..24: return 2; case 25..27: return 3; case 28..29: return 4; case 30..31: return 5; case 33..34: return 6; case 35..38: return 7; case 16..18, 39: return 8; case 41..43: return 9; case 11..15: return 10; case 44..46: return 11; case 40: return 12; } return -1; }