Jump to content
Sign in to follow this  
meatball

Interacting with Units created through site modules with script?

Recommended Posts

Wondering if it's possible in any way to interact with units that are autocreated by the sites modules in any way through scripting. For example, counting the total, checking the number alive, etc? There is an init field, but it doesn't look like the engine handles those groups of auto created units the same as normal.

For example, let's say I create a Blufor Observation Post Site module on my map which usually spawns 4 guys. In the init field I put "siteGuys = group this". Start the mission and the 4 Blufor units spawn as expected on the spot. But if I try doing a "units siteGuys" I get "[bIS_uniqueSite0]" as the array returned. If I try to "count siteGuys", I get only 1 for the count even though there's 4 guys.

Any thoughts?

Share this post


Link to post
Share on other sites

I'm very curious about this too.

I *think* the sites module uses a sort of caching to keep the numbers fresh. For instance I'm interested in tracking the animals site module... blufor shoot a bunch of the civ's sheep I want something bad to happen... Place an animal site module, shoot the sheep, leave the village, come back to the village, the sheep corpses are removed and a fresh "flock" of sheep are in their place, as if nothing ever happened... which isn't the real trouble. The real trouble is as you have suggested, it's difficult to come up with a way to track units, animals or people, that are placed with the sites.

Hope you share the answer, if you find one. I'm looking too.

Share this post


Link to post
Share on other sites

For the animal site module, this could work:

_site = <"object" used for Site>;
_cntSiteUnits = {(_x getVariable "inSite") == _site} count allUnits;

and for the outposts:

_site = <"object" used for Site>;
_groupsOfSite = _site getVariable "garrison";

_site should be in both cases the "object", read gamelogic name, used in editor.

_cntSiteUnits is the count of animals spawned from that sitelogic.

_groupsOfSite is an array of groups spawned from that sitelogic.

Isn't tested, so try your luck :)

greetings Na_Palm

Share this post


Link to post
Share on other sites

Thanks Na_Palm! I'll give that a try. :)

So when you say

_site should be in both cases the "object", read gamelogic name, used in editor.
you mean I need to name each module? These *are* modules we are talking about here... I'm not using any separate game logics?

Share this post


Link to post
Share on other sites

Yeah, I've been trying a bunch of different ways, but regardless of how many 'units' are spawned by any of the site modules, they don't appear to be tracked as individual entities. count allunits just goes up 1 no matter how many animal, unit, vehicle, etc are spawned.

Share this post


Link to post
Share on other sites

if you depbo ArmA3/addons/modules_f.pbo, you can look into the scripts for most modules, sites included.

@Oktyabr,

yes my bad, wanted to write module but somehow ended up with gamelogic. :)

Also i seem to have made another error, agents are not included in allUnits, they could be accessed with agents, instead.

So it would be:

_site = "object used for Site"; 
_cntSiteUnits = {(_x getVariable "inSite") == _site} count agents; 

I'am not entirely sure how rockets comment there would count into this...

@Meatball,

the sites seem to create more than one group per site, so to get the unit count, as an example it should work so:

_site = "object used for Site"; 
_groupsOfSite = _site getVariable "garrison";
_unitcount = 0;
{
   _unitcount = _unitcount + count units _x;
}forEach _groupsOfSite;

Edited by Na_Palm
forgot units in there

Share this post


Link to post
Share on other sites

Yeah, I can't seem to get either of those to work. The one that came the closest was "{(_x getVariable "inSite") == moduleName} count agents". At one point it did show the correct # of agents, but it never went down if I started killing the agents.

Guess I'll have to use another way to spawn units in these areas instead of using modules.

Share this post


Link to post
Share on other sites

The way seems to be right but I'am also a bit clueless then. Have you tried to place a trigger on the spot and count them with it?

greetings Na_Palm

Share this post


Link to post
Share on other sites

you could grab all the units using nearentities command and put them into an array so you could add/give whatever needed commands to them.

example : named site module - site1, change distance in near entities command to cover module radius

_men = (position site1) nearEntities ["Man", 100];
_siteGroup = [];
{if (alive _x && side _x == opfor) then {_siteGroup set [(count _siteGroup),_x];};} foreach _men;

result is an array of all alive opfor units in this case.

Share this post


Link to post
Share on other sites
you could grab all the units using nearentities command and put them into an array so you could add/give whatever needed commands to them.

example : named site module - site1, change distance in near entities command to cover module radius

_men = (position site1) nearEntities ["Man", 100];
_siteGroup = [];
{if (alive _x && side _x == opfor) then {_siteGroup set [(count _siteGroup),_x];};} foreach _men;

result is an array of all alive opfor units in this case.

Now that's clever! Thanks for the tip!

Share this post


Link to post
Share on other sites

How rough is nearestEntities on server/client resources if you used it in a trigger? For example, say you wanted to watch a goat population for some reason, I was thinking you could set up a site and then simply add something like this into the trigger condition:

count (goatSite nearEntities ["Goat_random_F",30]) <= 10;

Just don't know if that'll clobber the machine running the trigger check :)

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  

×