Checking if player has weapon, using an array or another method...
#1

Hi guys, im making a script to check what weapon a player has.


public TestWeapons(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++) {
if (IsPlayerConnected(i))
{
new pWeapon = GetPlayerWeapon(i);

if (Weapon == 8 || Weapon == 9 || Weapon == 16 || Weapon == 17 || Weapon == 21 || Weapon == 35 || Weapon == 36 || Weapon == 37 || Weapon == 38 || Weapon == 42) {
// Do something here
}
}
}
return 1;
}

But as you see, i have a lot if weapon == -number-... so can anybody help me make this job easy?
Thanks.
Reply
#2

if you want that the player cant use that weapons use this

pawn Код:
SetDisabledWeapons(gunid, ...)
Reply
#3

I want it as how i say it. Not disable or anything.
Reply
#4

Код:
new DetectWeapons[] = { 8, 9, 16, 17, 21, 35, 36, 47, 38, 42 };

public TestWeapons(playerid)
{
  for(new i = 0; i < MAX_PLAYERS; i++)
    if (IsPlayerConnected(i))
    {
      new pWeapon = GetPlayerWeapon(i);

      for (new i = 0; i < sizeof(DetectWeapons); i++)
        if (pWeapon == DetectWeapons[i])
        {
            // do something here
        }
    }
  return 1;
}
Reply
#5

Thanks!!!
Reply
#6

pawn Код:
switch (GetPlayerWeapon(i))
{
  case 8, 9, 16, 17, 21, 35, 36, 47, 38, 42 :
    //do something here
  default :
    //do something else
}
Far better than creating an array and searching in it with a loop...
Reply
#7

any objective reason why that may be? When compiled a switch is nothing else than a loop
Reply
#8

Quote:
Originally Posted by Rav
When compiled a switch is nothing else than a loop
No
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)