Checking if player has weapon, using an array or another method... -
Robbin237 - 15.02.2009
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.
Re: Checking if player has weapon, using an array or another method... -
Think - 15.02.2009
if you want that the player cant use that weapons use this
pawn Код:
SetDisabledWeapons(gunid, ...)
Re: Checking if player has weapon, using an array or another method... -
Robbin237 - 15.02.2009
I want it as how i say it. Not disable or anything.
Re: Checking if player has weapon, using an array or another method... -
[RP]Rav - 15.02.2009
Код:
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;
}
Re: Checking if player has weapon, using an array or another method... -
Robbin237 - 15.02.2009
Thanks!!!
Re: Checking if player has weapon, using an array or another method... -
yom - 15.02.2009
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...
Re: Checking if player has weapon, using an array or another method... -
[RP]Rav - 15.02.2009
any objective reason why that may be? When compiled a switch is nothing else than a loop
Re: Checking if player has weapon, using an array or another method... -
yom - 15.02.2009
Quote:
Originally Posted by Rav
When compiled a switch is nothing else than a loop
|
No