Jump to content
ArmaMan360

Enemies left hint for spawned units?

Recommended Posts

Problem is I am spawning units via DAC and SBGF garrison script. Unable to make the enemies hint happen this way :(

_values = ["z1",[1,0,0],[10,1,20,10],[1,1,5,4],[1,1,5,4],[],[1,1,1,1]]; // DAC lines
[_sidepos,_axis,_axis,0,0,_values] call DAC_fNewZone; // DAC Lines

sleep 0.6;

_units = [_sidepos,WEST,_axis,0.3,["B_Soldier_F","B_Soldier_lite_F","B_Soldier_GL_F","B_soldier_AR_F","B_Soldier_SL_F","B_Soldier_TL_F","B_soldier_M_F","B_soldier_LAT_F","B_medic_F","B_Soldier_A_F","B_soldier_AT_F","B_soldier_AA_F"]] call SBGF_fnc_garrison; // garrison script

sleep 0.5;

// Add task
//Task ID-Task name-Task description and some other options
[
	"Task1",
	true,
	["Clear the area by any means necessary.NATO have acquired a new base on the island. Finish them off quickly.","Clear Area","Clear Area"],
	_sidepos,
	"AUTOASSIGNED"
] call BIS_fnc_setTask;

sleep 20;

{
	if ((side _x) == West) then {
	enmc = _x;
	_x addEventHandler ["killed", {enmc = enmc -1; if (enmc != 0) then { hintsilent format["Enemy remaining : %1",enmc]}}]
	} forEach allUnits;
	sleep 2;
};

Thanks :)

Share this post


Link to post
Share on other sites

The hint is local to the unit you've assigned it to, use remoteExec or BIS_fnc_MP to broadcast it so everyone else can see it.

Share this post


Link to post
Share on other sites

The hint is local to the unit you've assigned it to, use remoteExec or BIS_fnc_MP to broadcast it so everyone else can see it.

I am sorry for not mentioning it, but this is a pure SP mission, and I am not sure about local or remoteExec. Please clarify :)

Share this post


Link to post
Share on other sites
Quoteif ((side _x) == West) then {
    enmc = _x;
    _x addEventHandler ["killed", {enmc = enmc -1; if (enmc != 0) then { hintsilent format["Enemy remaining : %1",enmc]}}]
    } forEach allUnits;
    sleep 2;


enmc = _x; That makes no sense. _x stores the unit which is currently used by the forEach loop.

 

You had a similar problems a few days ago. Your problem here is pretty much the same.

 

Does SBGF_fnc_garrison perchance return anything? Like the units it spawned ?

Share this post


Link to post
Share on other sites
Quoteif ((side _x) == West) then {
    enmc = _x;
    _x addEventHandler ["killed", {enmc = enmc -1; if (enmc != 0) then { hintsilent format["Enemy remaining : %1",enmc]}}]
    } forEach allUnits;
    sleep 2;


enmc = _x; That makes no sense. _x stores the unit which is currently used by the forEach loop.

 

You had a similar problems a few days ago. Your problem here is pretty much the same.

 

Does SBGF_fnc_garrison perchance return anything? Like the units it spawned ?

 

Yeah last time it was working on units spawned via one array _veh, hence it worked perfectly. This time its a combination of DAC lines to spawn normal enemy AI and SBGF is utilized for garrison. For SBGF we can do a "foreach _units" in above example, but what about AI Spawned via DAC? there is no variable before it.

 

Thats the reason I am doing a side check.

Share this post


Link to post
Share on other sites

I've never worked with DAC, therefore I can't really help you. However, if all your west units are enemies you could do something like this:

enmc = {side _x == west} count allUnits;

if ((side _x) == West) then {
    _x addEventHandler ["killed", {enmc = enmc -1; if (enmc != 0) then { hintsilent format["Enemy remaining : %1",enmc]}}]
    } forEach allUnits;
    sleep 2;

Share this post


Link to post
Share on other sites

 

I've never worked with DAC, therefore I can't really help you. However, if all your west units are enemies you could do something like this:

enmc = {side _x == west} count allUnits;

if ((side _x) == West) then {
    _x addEventHandler ["killed", {enmc = enmc -1; if (enmc != 0) then { hintsilent format["Enemy remaining : %1",enmc]}}]
    } forEach allUnits;
    sleep 2;

 

Throwing this:

enmc = {side _x == west} count allUnits;

if ((side #_x) == West) then {
....

Undefined variable under expression _x

Share this post


Link to post
Share on other sites

You can't use _x together with if. Basically my fault because I didn't correct that.

 

https://community.bistudio.com/wiki/Magic_Variables

 

 

The right syntax should be

enmc = {side _x == west} count allUnits;

{
    if ((side _x) == west) then
    {
        _x addEventHandler ["killed",
        {
            enmc = enmc -1;
            if (enmc != 0) then
            {
                hintsilent format["Enemy remaining : %1",enmc];
            };
        }];
    };
} forEach allUnits;
  • Like 1

Share this post


Link to post
Share on other sites

 

You can't use _x together with if. Basically my fault because I didn't correct that.

 

https://community.bistudio.com/wiki/Magic_Variables

 

 

The right syntax should be

enmc = {side _x == west} count allUnits;

{
    if ((side _x) == west) then
    {
        _x addEventHandler ["killed",
        {
            enmc = enmc -1;
            if (enmc != 0) then
            {
                hintsilent format["Enemy remaining : %1",enmc];
            };
        }];
    };
} forEach allUnits;

 

OMG sorry for the late reply R3vo.

 

Its working!

 

But, I tested this and appears it always leaves 1 enemy unit. I am running a "reveal.sqf" which puts a marker over every:

{alive _x && side _x == west} count allUnits;

to easily find that last annoying guy left in town :P

 

Still always get one soldier left and my reveal doesnt show any more left unit's marker. What I do see is a marker in the bottom left corner of the map. Because of this I have changed my task ending waitUntil from:

waitUntil {sleep 5; {alive  _x && side _x ==west} count allUnits == 0};

to this:

waitUntil {sleep 5; {alive  _x && side _x ==west} count allUnits < 3};

It doesnt hurt actually, just want to understand the cause.

Thank you.

Share this post


Link to post
Share on other sites

Hmm, probably an unit which is spawned by your garrison script? Have you checked if there truly is an unit at 0,0,0 ?

Share this post


Link to post
Share on other sites

Hmm, probably an unit which is spawned by your garrison script? Have you checked if there truly is an unit at 0,0,0 ?

I am not using any garrison script at the moment. I was using JShock's until I ran into a problem and ever since that line is commented out. Hopefully he will reply to my post at his script's thread. :)

 

Nonetheless, I donno whats causing it. BTW, does this code generate a complete integer rather than a decimal figure?:

(floor random 3 + 8)

I am using this to select the random number of infantry groups(0,1,2 or 3) over 8 to spawn. Using it in this:

_units = [_sidepos,_axis,(floor random 3 + 8),_vehi,_mech,_arm,_air] call JSHK_fnc_patrols;

No errors shown, but maybe it gives figures like 8 + 2.4 or 8 +1.2.. like this so its like an incomplete number and the script doesnt know what to do with such an unfinished group?

Share this post


Link to post
Share on other sites

Your method is fine, nothing wrong with it.

  • Like 1

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

×