Varn 0 Posted May 25, 2020 I am trying to figure out how to get a trigger to fire when a percentage of given items is in a specific area. I've been able to figure out how to get it to work if ONE item from a list is present or if ALL the items are present, but I want to give my player some leeway in the number of items they have to collect. One of the primary mission objectives for the mission is for the players to drive around and collect a bunch of items and bring them back to their starting area. Because some of these items are destructible and there are a lot of them, I wanted to only require the collection of maybe 50 or 75% of them in order for the mission to be a success. I've tried googling and searching the forums but can't seem to find anything to help with this exact scenario. Share this post Link to post Share on other sites
opusfmspol 282 Posted May 25, 2020 // 75% or more in area. Count _itemsInArea >= ((Count _itemsTotal) * 0.75) 1 Share this post Link to post Share on other sites
Varn 0 Posted May 25, 2020 How do I get that to work with specifically labeled items though? Like if I have 10-15 specifically named/labeled items how do i get it to work with just those items? Share this post Link to post Share on other sites
Harzach 2517 Posted May 25, 2020 Place those items in an array and adopt @opusfmspol's snippet. _itemsTotal = [<your item variable names here>]; Count _itemsInArea >= ((Count _itemsTotal) * 0.75) 1 Share this post Link to post Share on other sites
Varn 0 Posted May 25, 2020 Thanks, I know next to nothing about coding and scripting so most things just kind of go over my head. For the array, do I need to use anything to split the item names like a common or semi colon or will spaces work just fine? And the code goes in the activation area on the trigger area right? Share this post Link to post Share on other sites
Harzach 2517 Posted May 25, 2020 If your objects were named "item_1" through "item_15" then your array would look something like this: _itemsTotal = [item_1, item_2, item_3, item_4, item_5, item_6, item_7, item_8, item_9, item_10, item_11, item_12, item_13, item_14, item_15]; So just commas between each element. The space is not necessary, but helps with readability. The array needs to be defined somewhere, and the "Count" line goes in the trigger's condition field. You can define the array in any number of locations, though it might depend upon whether the mission is SP/MP. You could place that line in the init field of an object, or in an init script, or even another trigger that fires when the mission starts. 1 Share this post Link to post Share on other sites
Harzach 2517 Posted May 25, 2020 Actually, this isn't going to work at all until we fix a few things. Be back in a bit! BTW, what items are you using and how do you want to count them as present (placed in a box, dropped inside an area, etc)? Share this post Link to post Share on other sites
Varn 0 Posted May 25, 2020 Alright, I'm going something wrong. For testing purposes I set it up with 4 items name o1,o2,o3, and o4. _itemsTotal = [o1, o2, o3, o4]; Count _itemsInArea >= ((Count _itemsTotal) * 0.75) I have that in the "Condition" box on the trigger, with the trigger set to give a hint so that I know if it went off, and it's not going off. Share this post Link to post Share on other sites
Varn 0 Posted May 25, 2020 15 minutes ago, Harzach said: Actually, this isn't going to work at all until we fix a few things. Be back in a bit! BTW, what items are you using and how do you want to count them as present (placed in a box, dropped inside an area, etc)? I plan on using a mixture of IDAP supplies (boxes, food stacks, water pallet) and ammo crates. The idea is that the players are raiding supply caches and need to take the supplies back to their base. I'm even thinking of including a few special vehicles for them to capture (water/fuel truck or ambulance). Preferably I'd like the items to count even if they are stored as cargo in a vehicle, but if they need to be unloaded that's not a problem. Share this post Link to post Share on other sites
opusfmspol 282 Posted May 25, 2020 Beginners Guide on Arrays A3 Script Commands 2 minutes ago, Varn said: I have that in the "Condition" box on the trigger, with the trigger set to give a hint so that I know if it went off, and it's not going off. Because _itemsInArea is undefined (also see note). - Define the array of all items, either as ItemsTotal or _itemsTotal (note: editor triggers don't allow the "_local" variable type in primary scope, but triggers created by scripts do). ItemsTotal = [item_1, item_2, item_3, item_4]; - Build an array of the items that are in the area: either as ItemsInArea or _itemsInArea: ItemsInArea = []; {if (_x In thisList) then {ItemsInArea pushBack [_x]};} Count ItemsTotal; - Then determine if number in area meets the desired percentage: Count itemsInArea >= ((Count itemsTotal) * 0.75) That should count the editor placed items, but counting the cargo items in objects needs more. 1 Share this post Link to post Share on other sites
Varn 0 Posted May 25, 2020 3 minutes ago, opusfmspol said: Beginners Guide on Arrays A3 Script Commands Because _itemsInArea is undefined (also see note). - Define the array of all items, either as ItemsTotal or _itemsTotal (note: editor triggers don't allow the "_local" variable type in primary scope, but triggers created by scripts do). ItemsTotal = [item_1, item_2, item_3, item_4]; - Build an array of the items that are in the area: either as ItemsInArea or _itemsInArea: ItemsInArea = []; {if (_x In thisList) then {ItemsInArea pushBack [_x]};} Count ItemsTotal; - Then determine if number in area meets the desired percentage: Count itemsInArea >= ((Count itemsTotal) * 0.75) That should count the editor placed items, but counting the cargo items in objects needs more. I have no idea what any of this means. Could you please break it down and explain exactly where what bits of code are supposed to go? Share this post Link to post Share on other sites
Harzach 2517 Posted May 25, 2020 15 minutes ago, Varn said: I plan on using a mixture of IDAP supplies (boxes, food stacks, water pallet) and ammo crates. How are you moving these objects from one place to another? You have set yourself quite a challenge. Share this post Link to post Share on other sites
Varn 0 Posted May 25, 2020 3 minutes ago, Harzach said: How are you moving these objects from one place to another? You have set yourself quite a challenge. Using ACE to load them into vehicles. If they need to be unloaded to count then that's not a problem. Share this post Link to post Share on other sites
opusfmspol 282 Posted May 25, 2020 Crawl, then walk, then run. Untested, but try this in trigger condition: ItemsTotal = [o1, o2, o3, o4]; ItemsInArea = []; {if (_x In thisList) then {ItemsInArea pushBack [_x]};} Count ItemsTotal; Count itemsInArea >= ((Count itemsTotal) * 0.75) Should trigger when 3+ items are in trigger area. But as said, counting cargo items will need more. 1 Share this post Link to post Share on other sites
Varn 0 Posted May 25, 2020 6 minutes ago, opusfmspol said: Crawl, then walk, then run. Untested, but try this in trigger condition: ItemsTotal = [o1, o2, o3, o4]; ItemsInArea = []; {if (_x In thisList) then {ItemsInArea pushBack [_x]};} Count ItemsTotal; Count itemsInArea >= ((Count itemsTotal) * 0.75) Should trigger when 3+ items are in trigger area. But as said, counting cargo items will need more. Does not work. Share this post Link to post Share on other sites
Harzach 2517 Posted May 25, 2020 You can't run code in the condition field, only boolean expressions. Share this post Link to post Share on other sites
Varn 0 Posted May 25, 2020 1 minute ago, Harzach said: You can't run code in the condition field, only boolean expressions. Does that mean I need to run the code in a separate sqm file using execVM in the trigger? Share this post Link to post Share on other sites
Harzach 2517 Posted May 25, 2020 25 minutes ago, Varn said: Does that mean I need to run the code in a separate sqm file using execVM in the trigger? Nope! Anyway, easy-peasy.As stated previously, you must define the array somewhere outside of the trigger. For example, in another trigger, simply change the condition field to "true" then define the array in the onAct field: itemArray = [item_1, item_2, item_3,...etc]; That done, in the trigger's condition field, place this: ({_x inArea thisTrigger} count itemArray >= (count itemArray * 0.75)) Tested. 2 Share this post Link to post Share on other sites
Varn 0 Posted May 25, 2020 I'm getting an error "Invalid number in expression" for the count trigger And this will be for an online multiplayer mission hosted on my machine Share this post Link to post Share on other sites
opusfmspol 282 Posted May 25, 2020 31 minutes ago, Harzach said: You can't run code in the condition field, only boolean expressions. You can, a = true; b = false; a || b works a = 2; b = 1; a >= b also works I was in error thinking triggers would list empty objects. Apparently they don't. Also, pushBack gets me every time, would have been pushback _x instead of pushback [_x] if had been used correctly. I'm always stuck with array = array + [_x] in my head. @Harzach has it right. Tested and this appears to work in condition field: ItemsTotal = [o1, o2, o3, o4]; ({_x inArea thisTrigger} Count ItemsTotal) >= ((Count itemsTotal) * 0.75) 2 Share this post Link to post Share on other sites
Varn 0 Posted May 25, 2020 3 minutes ago, opusfmspol said: Tested and this appears to work in condition field: ItemsTotal = [o1, o2, o3, o4]; ({_x inArea thisTrigger} Count ItemsTotal) >= ((Count itemsTotal) * 0.75) THAT worked. Thank you very much to the both of you for putting up with me. Share this post Link to post Share on other sites
Harzach 2517 Posted May 25, 2020 1 hour ago, opusfmspol said: You can, a = true; b = false; a || b works Hmm, interesting. That's kind of dangerous since the condition field is calculated every half-second or so. I'd have to imagine that best practice would be not to run code there. 1 Share this post Link to post Share on other sites
opusfmspol 282 Posted May 26, 2020 6 hours ago, Harzach said: I'd have to imagine that best practice would be not to run code there. If its an unchanging value, as the items list here appears to be, best practice is definitely to predefine the value in an init script. Maintain it in a separate process, if necessary. Sometimes running code ahead of evaluating condition is needed and helpful for getting condition values. In this case, trying to find what works, it's helpful. But you've got it right, whenever possible best practice is to use condition alone. Array should be predefined elsewhere and trigger should just run the condition check. 2 Share this post Link to post Share on other sites
Varn 0 Posted May 26, 2020 As a sort of follow up to this, is there a way to have a trigger fire when ANY unit is killed in a given area? Or would I need to put every unit in an array and have the trigger check the array? Would it be any easier to set a trigger to fire when a unit from a specific side is killed anywhere on the map for it to set the trigger off? The idea is that if any of my player kills a Civilian or Independent unit (which start friendly to them) then it would trigger a side change to make them hostile. I've got the side change down using: _allIndforGroups = allgroups select {side _x isEqualTo resistance}; _allIndforGroups apply {_grp = creategroup east;units _x joinSilent _grp}; And it seems to work, but I'm not sure how to trigger it (easily) without a very long list of "!alive unitname or" Share this post Link to post Share on other sites
Harzach 2517 Posted May 26, 2020 Skip the trigger and use an event handler. The EntityKilled MEH might be a good place to start. Just evaluate the side of _killed and check if _instigator/_killer is a player. 1 Share this post Link to post Share on other sites