Home   Help Search Login Register  

Author Topic: Has a weapon  (Read 1925 times)

0 Members and 1 Guest are viewing this topic.

Offline ZapBrannigan

  • Members
  • *
Has a weapon
« on: 16 Oct 2007, 03:01:57 »
hey,

I need to detect if the player has a weapon, I see this command hasweapon, but that seems to only check for certain weapons, How can I detect in a trigger if the player has any weapon?

thanks

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Has a weapon
« Reply #1 on: 16 Oct 2007, 08:46:33 »
Code: [Select]
(count (weapons player))
The problem is though that binoculars and nvgoggles are weapons as well so that will return 1 even if the unit has no firearms at all, just binocs or nvgoggles in it's inventory..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Has a weapon
« Reply #2 on: 16 Oct 2007, 10:24:13 »
try
Code: [Select]
?canFire player: ...

Offline ZapBrannigan

  • Members
  • *
Re: Has a weapon
« Reply #3 on: 17 Oct 2007, 03:57:15 »
dosent work, it activates even if I dont have a weapon. thanks

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Has a weapon
« Reply #4 on: 17 Oct 2007, 09:27:05 »
How about that count thing I suggested?

You can bypass the binoc nvg problem by using this in the trigger's condition field
Quote
(count (weapons player - ["NVGoggles","Binocular"]))<1
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Has a weapon
« Reply #5 on: 17 Oct 2007, 12:36:11 »
What about laser designators, the telephone, normal and/or smoke grenades (though how do people know what type of grenade you have in your pocket at 100m?) or non-BIS items? You could just remove all the non-deadly weapons you know about or use SPON_getWeaponType which is a more generic, though still imperfect, solution (doesn't account for smoke grenades):
Code: [Select]
_hasDeadlyWeapon = { ([_x] call SPON_getWeaponType) in ["PISTOL", "RIFLE", "LAUNCHER", "GRENADE", "PUT"] } count (weapons player)) > 0;

[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Cheetah

  • Former Staff
  • ****
Re: Has a weapon
« Reply #6 on: 17 Oct 2007, 23:07:27 »
Not sure if mandoble's my weapon returns 'nothing' when the player has no weapon. If it does, you can check for that condition.

You'll have to check if it returns 'nothing' , 'null' etc.
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline ZapBrannigan

  • Members
  • *
Re: Has a weapon
« Reply #7 on: 18 Oct 2007, 00:32:32 »
well I dont have to worry about NVG or binocs because the only weapon the player can get is a rifle and ammo.

so how would I use (count (weapons player))?

?(count (weapons player))> 1: t1 = true

and then I can use

? t1: do whatever i want


will this work?

thanks

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Has a weapon
« Reply #8 on: 18 Oct 2007, 01:37:55 »
Well, weapons gives an array of all weapons that the person is carrying and count tells you how many items are in the array. In your case, you only need the array to contain something for the person to be armed.
Code: (SQS) [Select]
? (count (weapons player)) > 0 ? do stuff
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline ZapBrannigan

  • Members
  • *
Re: Has a weapon
« Reply #9 on: 18 Oct 2007, 06:00:09 »
works great, thanks guys