doc. caliban 34 Posted March 22, 2017 I run some code against every leader of a group on the specified side. { if (side _x in [INDEPENDENT]) then { private _unit = leader _x; _x ...; } } forEach allGroups; I need to omit any units who are in a vehicle. Would this be a way to do it? { if (side _x in [INDEPENDENT]) then { private _unit = leader _x; if (isNull objectParent _unit) then { _x ...; }; } } forEach allGroups; As usual, ignore the indentation ... this code window is just annoying about that. :-) -Doc EDIT: Actually, that seems to work. Is there a better way to do it? Share this post Link to post Share on other sites
BlacKnightBK 47 Posted March 22, 2017 1 hour ago, doc. caliban said: I run some code against every leader of a group on the specified side. { if (side _x in [INDEPENDENT]) then { private _unit = leader _x; _x ...; } } forEach allGroups; I need to omit any units who are in a vehicle. Would this be a way to do it? { if (side _x in [INDEPENDENT]) then { private _unit = leader _x; if (isNull objectParent _unit) then { _x ...; }; } } forEach allGroups; As usual, ignore the indentation ... this code window is just annoying about that. :-) -Doc EDIT: Actually, that seems to work. Is there a better way to do it? You can create an array which contains units that are in the vehicle. The units will be added to the array using an eventHandler. Run your code on all units that are not in that array My personal opinion. I am still just a newbie probably the experts will have better solutions Cheers Share this post Link to post Share on other sites
cremaster34 10 Posted March 22, 2017 If a unit is in an vehicle then: _unit != (vehicle _unit) So to omit units who are mounted you might write: If(_unit == (vehicle _unit)) then { _x ...; }; Share this post Link to post Share on other sites
Midnighters 152 Posted March 22, 2017 the first code block would be checking to see if the group's side as inside the array independent. Which independent isn't an array and is just a side. so if you were to do : unitsInVehicles = []; { if((side _x) == (independent)) then { if(_unit == (vehicle _unit)) then { unitsInVehicles append _unit; }; }; } forEach allGroups; hint format["%1",(unitsInVehicles)]; that'll be your general concept of this all. Not sure what you're trying to do exactly. Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted March 22, 2017 Just now, Midnighters said: the first code block would be checking to see if the group's side as inside the array independent. Which independent isn't an array and is just a side. so if you were to do : unitsInVehicles = []; { if(_unit == (vehicle _unit)) then { unitsInVehicles append _unit; }; } forEach allGroups; hint format["%1",(unitsInVehicles)]; that'll be your general concept of this all. Not sure what you're trying to do exactly. Won't work, since append requires two arrays. Nothing wrong with the objectParents check. unitsInVehicles = []; { if (side _x isEqualTo INDEPENDENT) then { private _unit = leader _x; if (isNull objectParent _unit) then { unitsInVehicles pushBackUnique _unit; }; } } forEach allGroups; This could work too: unitsInVehicles = allUnits select {side _x isEqualTo INDEPENDENT AND !(isNull objectParent _x)}; Cheers 1 Share this post Link to post Share on other sites
Midnighters 152 Posted March 22, 2017 2 minutes ago, Grumpy Old Man said: Won't work, since append requires two arrays. Nothing wrong with the objectParents check. unitsInVehicles = []; { if (side _x isEqualTo INDEPENDENT) then { private _unit = leader _x; if (isNull objectParent _unit) then { unitsInVehicles pushBackUnique _x; }; } } forEach allGroups; Cheers Shucks man, forgot about that. Thanks. yeah i've never used objectParents to check. But I dont think the code used above was used correctly, since you'd need to find the object parent of the vehicle? Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted March 22, 2017 Not sure what you mean, I just noticed the example above iterated through all groups, did a small correction and added an alternative way to check, since it doesn't make sense to check if only group leaders are inside a vehicle when the request was to put all units that are inside a vehicle in an array. Cheers Share this post Link to post Share on other sites
Midnighters 152 Posted March 22, 2017 Just now, Grumpy Old Man said: Not sure what you mean, I just noticed the example above iterated through all groups, did a small correction and added an alternative way to check, since it doesn't make sense to check if only group leaders are inside a vehicle when the request was to put all units that are inside a vehicle in an array. Cheers Well my brain must be asleep in some sense or another, I see what you mean now. Share this post Link to post Share on other sites
doc. caliban 34 Posted March 22, 2017 Thank you for all of the replies, guys! This is great. I use the scrip-only version of the Gaia AI mod, which requires the INIT of each Team Leader to have some things added. Without going into the details, I've automated most of the process to make mission creation faster due to less manual editing. The exceptions are vehicles and their crews. In that case, the vehicle gets the INIT input and the Team Leader does not. I manually enter the vehicle data because there are only a few of them and I want to do very specific things with them, but if I run my automation script without omitting Team Leaders of vehicle crews, they end up getting the INIT info applied to them, which derails the INIT of the vehicle and its behavior. Make sense so far? That's why I need to make sure that my script does its thing (the "..." in my original post) for every Team Leader on a side or sides, but skips vehicle crews altogether. I will read up on pushBackUnique! Thanks again, -Doc Share this post Link to post Share on other sites