Jump to content
Maguila.gm

Multiple Enemy units to ping on the map

Recommended Posts

I had a script to one enemy unit to ping on the map and have its position updated every 5 seconds and it worked:

 

beaconblip1 = createMarker ["beacon1", v1];
beaconblip1 setMarkerShape "ELLIPSE";
beaconblip1 setMarkerColor "ColorGreen";
beaconblip1 setMarkerSize [15, 15];
while {true} do {
 "beacon1" setMarkerPos (getPos v1);
sleep 5;
};

 

I wanted do do for multiple units, i did multiple of the exemple 1 but after 20 or so it got very time consuming. So i did this and it is not working:

 

// Define the array of enemy unit objects (replace these with your actual enemy unit objects)
private _enemyUnits = [v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21];

// Create an empty array to hold the markers
private _markers = [];

// Create markers for each enemy unit
{
    private _markerName = format ["enemyMarker%d", (_forEachIndex + 1)];
    private _markerPos = getPos _x;

    _markers pushBack createMarker [_markerName, _markerPos];
    _markers select (_forEachIndex) setMarkerShape "ELLIPSE";
    _markers select (_forEachIndex) setMarkerColor "ColorRed"; // You can set this to whatever color you prefer
    _markers select (_forEachIndex) setMarkerSize [15, 15];
} forEach _enemyUnits;

// Continuously update the marker positions based on enemy unit positions
while {true} do {
    {
        private _markerName = format ["enemyMarker%d", (_forEachIndex + 1)];
        _markerName setMarkerPos (getPos (_enemyUnits select _forEachIndex));
    } forEach _enemyUnits;
    
    sleep 5;
};
 

 

Share this post


Link to post
Share on other sites

Welcome on forum.

2 errors:

You didn't set _markers before using it (missing line:  _markers = []; )

and your format (for marker name) is wrong : replace it everywhere by: format ["enemyMarker%1", (_forEachIndex + 1)]   (instead of "enemyMarker%d")

Note: you need to spawn this code, using a while true loop.

 

Anyway, you can easily avoid such names for markers. str random 1 will return different strings, no matter the number of markers. Test it.

My suggest (tested):

private _enemyUnits = [v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21];
{
  private _mk = createMarker [str random 1, getpos _x];
  _mk setMarkerShape "ELLIPSE";
  _mk setMarkerColor "colorRed";
  _mk setMarkerSize [15,15];
  [_mk,_x] spawn {
    params ["_mk","_enemy"];
    while {alive _enemy} do {
      _mk setMarkerPos _enemy;
      sleep 5;
    };
    deleteMarker _mk;
  };
} forEach _enemyUnits;

 

  • Like 2

Share this post


Link to post
Share on other sites
private _enemyUnits = [v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50];
{
  private _mk = createMarker [str random 1, getpos _x];
  _mk setMarkerShape "ELLIPSE";
  _mk setMarkerColor "colorRed";
  _mk setMarkerSize [15,15];
  [_mk,_x] spawn {
    params ["_mk","_enemy"];
    while {damage _enemy < 1} do {
      _mk setMarkerPos _enemy;
      sleep 5;
    };
    deleteMarker _mk;
  };
} forEach _enemyUnits

Sorry to bother, but the code above is not running, do you know what is wrong

Share this post


Link to post
Share on other sites
2 hours ago, Maguila.gm said:

do you know what is wrong

 

No closing semicolon and a few corrupted characters:

 

95GjjYr.png

 

When you paste code into a code block, corrupted/invisible characters show up as red dots. You can just delete them then recopy your code out of the code block.

  • Like 1

Share this post


Link to post
Share on other sites

Little bit odd naming 50 units as enemies...

Why not replacing this array by a side condition?

  • Like 1

Share this post


Link to post
Share on other sites
9 minutes ago, pierremgi said:

Little bit odd naming 50 units as enemies...

Why not replacing this array by a side condition?

I just wanted armoured vehicles to show up. but yes haha i know nothin to very little of coding and editing so most time i do things that are not the best

Share this post


Link to post
Share on other sites

If all these vehicles are edited (not spawned during the game), you can write something like:

private _enemyUnits = vehicles select {side _x == EAST && _x isKindOf "tank"};

 

  • Like 1

Share this post


Link to post
Share on other sites
19 hours ago, pierremgi said:

If all these vehicles are edited (not spawned during the game), you can write something like:


private _enemyUnits = vehicles select {side _x == EAST && _x isKindOf "tank"};

 

Thanks, i had no idea i could do such a thing...

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

×