Jump to content
Cryptdik

Calling a function on all units on the map?

Recommended Posts

Hey, so I'm trying to make it so SimpleShops's kill rewards works on AI and players alike. It says that you call it by placing this in a unit's init box:
https://github.com/Ppgtjmad/SimpleShops/wiki/Kill-Rewards

[this] call HG_fnc_aiUnitSetup;

I'm trying to adapt this so that I can use it with Zeus and other unit spawning scripts so that it works specifically by just running the function on every unit on the map. I was thinking of doing this by making a repeatable trigger that encompasses the entire map that should call this function on the unit that enters it once, but I can't get it to work. What I tried is making a trigger with Anybody present conditions and OnActivation does:
 

{[this] call HG_fnc_aiUnitSetup} forEach thislist;

Nothing I've tried has worked yet. I just need it to run on every unit that spawns on the map or enters a large enough trigger, any tips are appreciated!

 

EDIT: I got it working using the following, BUT I'm getting a strange performance issue where the script must be running constantly. I might need to edit it so it only runs on a unit one time, and only when it spawns/enters the trigger.

{_x call HG_fnc_aiUnitSetup} forEach thislist;


 

Share this post


Link to post
Share on other sites

You need a way to check that the HG_fnc_aiUnitSetup is not run on unit already. setvariable is one way to do this:


 

{

if(!(_x getVariable ["aiSetupDone",false])) then
{

_x call HG_fnc_aiUnitSetup;

_x setVariable ["aiSetupDone",true];

};

} forEach thislist;

code not tested, hope it works

Share this post


Link to post
Share on other sites

Hmm, I'm getting a missing ";" although I can't see for the life of me where it's missing a semi-colon.

Share this post


Link to post
Share on other sites

@Cryptdik,
What's in the list?

Spoiler

{

if(!(_x getVariable ["aiSetupDone",false])) then
{

_x call HG_fnc_aiUnitSetup;

_x setVariable ["aiSetupDone",true];

};

} forEach units thislist;

units?

Have fun!

Share this post


Link to post
Share on other sites

I still get the same error, this is the popup:

'...)) then
{

_x call HG_fnc_aiUnitSetup|#|;

_x setVariable ["aiSetupDone"...'
Error Missing ;

I got the trigger to repeat every 5 seconds and it's working with Zeus spawned units now if they're alive long enough for the trigger to repeat. However, it seems to be stacking on units so that the longer they're alive the more money they yield, so the last part is getting it only to run once on them correctly.
 

Condition: 
this and var1

OnAct:
{_x call HG_fnc_aiUnitSetup} forEach thislist; var1=false; hint "trigger";

On Deact:
var1=tru

Timer - 5 second countdown
Repeatable [x]


Also, I've noticed that it doesn't seem to affect vehicles from what I can tell, which would be cool but isn't a requirement, as long as players can earn money by killing enemy men I'll be satisfied. I just still can't figure out why it says it's missing a semi-colon in your solution..
Thanks a huge amount for the help btw!

  • Like 1

Share this post


Link to post
Share on other sites

where is HG_fnc_aiUnitSetup defined? it maybe that the HG_fnc_aiUnitSetup is not yet defined when your trigger runs the code. Not sure, I rarely use triggers

Share this post


Link to post
Share on other sites

I'm not sure, I looked through some of the files that Simple Shops comes with and couldn't find it. Maybe using a script that repeats would be easier than using a trigger? Although that's a whole new bag of trouble for me to try to work out ;_;

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

×