Jump to content
Sign in to follow this  
zilfondel

Trigger issue - hasweapon count array

Recommended Posts

I don't post here often, but I am trying to create a trigger to check if a unit is carrying a pistol. Mostly trying to learn how to properly use arrays and commands. I am trying to do as much as possible within the editor instead of using scripts, as I am still learning the basics. This is for a MP mission.

I have a gamelogic which declares a list of pistol classnames, including the m9:

pistol_list = ["m9"];

And I have experimented with triggers to detect whether or not my unit, part of group uct, is carrying one of the pistols.

This works:

{player hasweapon _x} count pistol_list > 0

This also works - but doesn't use the pistol_list:

{_x hasWeapon "m9"} count (units uct) > 0

How do I combine the two expressions together? I would rather not have to insert a trigger for every team member or insert every pistol type into the trigger. I also want to understand how the heck to properly script expressions like these.

I tried this and it failed with a "Error Generic error in expression":

{_x hasWeapon ["_x count pistol_list"]} count (units uct) > 0

I have pulled most of my code from kylania's undercover mission example: http://www.kylania.com/ex/?p=98

As well as this thread: http://forums.bistudio.com/showthread.php?118990-Detect-if-a-unit-has-any-weapon

Ultimately, my mission will have an undercover team that loses its 'setcaptive' status whenever they fire a weapon, hold a pistol, or have a primary or secondary weapon. Just for one specific group of players.

Thank you.

Share this post


Link to post
Share on other sites

So, my question is, how do I make a trigger check every unit in a group to see if they have any weapons that I have defined in the array "pistol_list"? Or, is there a better way of doing this?

Any help would be appreciated! Or, if there are resources I could learn to improve my scripting, that would be a huge plus!

Share this post


Link to post
Share on other sites

I'm not really sure I understand.

If you only want to check for the M9, you've basically covered that already.

If you want to check for more pistols, there's really no easy way to "combine" it since hasWeapon wants a string, not an array.

A combination could look like this.

//logic or whatever
pistol_list = ["m9","m9sd"];

//trigger
({_x hasWeapon (pistol_list select 0) || _x hasWeapon (pistol_list select 1)} count (units uct)) > 0

Edited by cuel

Share this post


Link to post
Share on other sites

Thanks for the response - yeah, I was hoping to define a list of several different pistol classnames in the array, and check every unit in my group "uct" to see if any of them are carrying one of the pistols in the list (hence the > 0).

ie:

pistol_list = ["m9","glock17_EP1","Colt1911","Makarov","Colt1911"]

I was doing this because, from what I have researched, the check for primaryweapons ignore pistols, and I have been able to successfully set triggers to detect primary and secondary weapons.

Edited by Justino

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×