OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: D_P_ on 20 Sep 2007, 02:55:03

Title: detect if player has weapon or not?
Post by: D_P_ on 20 Sep 2007, 02:55:03
I need to find out if the player in my mission is carrying a gun or not when he activates a script....to get the animation/sounds to sync. Anyone know how I'd do this? thx
Title: Re: detect if player has weapon or not?
Post by: LeeHunt on 20 Sep 2007, 02:58:33
This may help, however I believe it only detects a certain type of weapon.  So you might have to repeat the code ? (player hasWeapon "M16") : goto "ready" multiple times for each type of weapon the player picks up. There may be a better solution out there using primaryweapon but i know this will work (have used it myself) if you keep repeating the code for different weapon types...

http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=h#hasWeapon

unit hasWeapon weaponName
Operand types:
unit: Object
weaponName: String

Type of returned value:
Boolean
Description:
Check if unit has given weapon.
Used In:
ArmA/OFP
Example:
? (player hasWeapon "M16") : goto "ready"
Title: Re: detect if player has weapon or not?
Post by: LCD on 20 Sep 2007, 10:05:24
cud use da primaryweapon (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=p#primaryWeapon) command :D

now unless he has a handgund and he is usin it it wud work 4 u :D

LCD OUT
Title: Re: detect if player has weapon or not?
Post by: Mandoble on 20 Sep 2007, 14:09:07
Do you mean if the player has a particular weapon in the hands? or just of the player has a particular weapon in his inventory?
Title: Re: detect if player has weapon or not?
Post by: D_P_ on 21 Sep 2007, 02:33:03
Thanks for the speedy replies :D

I will try the above and see if it does the trick.

@Mandoble: I mean in his hand and/or inventory.

He starts with no weapons...then after completing a few objectives...finds a weapon. I have some cut scenes where he can stop and examine objects...the animations/sounds in the cutscenes are timed perfectly...provided he has no weapons in his hands. When he does have a weapon, he first has to holster the weapon and then perform the animation...this delay makes all the actions in the cutscene off cue =(

Anyway - I'll try the above advice and hopefully can get this mission moving along.
Thanks
Title: Re: detect if player has weapon or not?
Post by: Planck on 21 Sep 2007, 13:32:52
weapons should give you an array of all a vehicles weapons.

_wArray = weapons player

If the array is empty he has no weapons I suppose, although I imagine binoculars or nvg's might count as weapons too.


Planck
Title: Re: detect if player has weapon or not?
Post by: D_P_ on 26 Sep 2007, 02:39:28
Code: [Select]
? (player hasWeapon "M16") : goto "ready"
Works perfectly.  :)