SA-MP Forums Archive
If not holding a melee weapon - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: If not holding a melee weapon (/showthread.php?tid=442413)



If not holding a melee weapon - Sellize - 07.06.2013

I made it this way http://pastebin.com/mi1wWNT5

Could i have done it more efficient?


Re: If not holding a melee weapon - -CaRRoT - 07.06.2013

What about using && ?

Something like this -

PHP код:
 if(GetPlayerWeapon(playerid) != 10 && GetPlayerWeapon(playerid) != 11
Not sure if it would work but I guess it can be done somehow - However , Kinda better.


Re: If not holding a melee weapon - Sellize - 07.06.2013

Quote:
Originally Posted by -CaRRoT
Посмотреть сообщение
What about using && ?

Something like this -

PHP код:
 if(GetPlayerWeapon(playerid) != 10 && GetPlayerWeapon(playerid) != 11
Not sure if it would work but I guess it can be done somehow - However , Kinda better.
Yeah could've done that but I love doing identation and stuff :d


Re: If not holding a melee weapon - Tingesport - 07.06.2013

Don't know if that works, make a array of all melee weapons and then a loop.

pawn Код:
for(new w = 0; w < 46; w++) // LOOPS 1 > 45
    {
          if(GetPlayerWeapon(playerid) != w)
         // AND SOME OTHER SHIT HERE, lulz.
    }



Re: If not holding a melee weapon - Sellize - 07.06.2013

Quote:
Originally Posted by Tingesport
Посмотреть сообщение
Don't know if that works, make a array of all melee weapons and then a loop.

pawn Код:
for(new w = 0; w < 46; w++) // LOOPS 1 > 45
    {
          if(GetPlayerWeapon(playerid) != w)
         // AND SOME OTHER SHIT HERE, lulz.
    }
Thats a much faster way but mine works too, just tested it


Re: If not holding a melee weapon - Vince - 07.06.2013

A switch statement would work even faster as you only need to call GetPlayerWeapon once. And also much less code.
(Not saying that less code is always better, but in this case it definitely is.)

pawn Код:
switch(GetPlayerWeapon(playerid))
{
    case 0..18,36,37,39,40..46: { /* melee */ }
    default: { /* not melee */ }
}