Jump to content
reggaeman007jah

Repeatable Markers [Solved]

Recommended Posts

Hello folks, 

 

I am hoping for a bit of help with something - apologies, this is very basic stuff, but I just can't get this to work.

 

I have three markers that I want to select randomly, using addAction. I have the marker XY positions in an array, and am trying to populate the positions randomly every time (i.e. generate random markers per addAction).

 

This is what I have currently:

 

Spoiler

_markers = [[18900.377, 9386.781],[17769.525, 9223.61],[20404.086, 9279.7641]];
_rnd = floor (random 3);
_lzPos = _markers select _rnd;
_lzMarker = createMarker ["landingZone", _lzPos];
"landingZone" setMarkerText "LZ Test";
"landingZone" setMarkerType "hd_pickup";
"landingZone" setMarkerColor "ColorRed";

 

This works to a degree; when I restart a mission, it does show a random marker. But when I reactivate the addAction subsequently, it does not change.

 

I am sorry to bring such a basic question to this great forum, but it is driving me crazy. Can anyone point out the (my) obvious stupidity here? :)

 

Cheers

RM

Share this post


Link to post
Share on other sites

Well, createMarker wont do anything if a marker with that name already exists.

 

If you want multiple markers you'll have to use a dynamic name (number at the end)

Or if you just want to update this one marker, add a setMarkerPos line to it.

  • Like 1

Share this post


Link to post
Share on other sites

Hey @Tajin, thanks for replying :)

 

So, I am building a basic heli mission, where you go from LZ to LZ, picking up and dropping off AI dudes.

 

I have a bunch of suitable map locations scoped out already, and will eventually build the locations into the script - the idea is that once you land at an LZ, you'll be given another random LZ (from the array) to go to next. 

 

I'm planning about 20 or 30 locations in the region, so the only rule would be that your next drop-off point should not be the marker you've currently landed on. Once a marker is created, I have units, smoke, flares, enemy etc to keep things interesting.


So, when I start off the mission in the editor, I have no markers on the map. Ideally I want to run the addAction command to create the first marker location from the array (which would then initiate the bells and whistles, units, ambience etc). Once at said marker, I would hit addAction again to get a new marker to go to.

 

To do this ^^ would I need to delete the recently created marker, before a new one could be generated?

 

Sorry if that is a bit unclear..

 

*** edit ***

 

So this works:

 

Spoiler

deleteMarker "landingZone";
_markers = [[18900.377, 9386.781],[17769.525, 9223.61],[20404.086, 9279.7641]];
_rnd = floor (random 3);
_lzPos = _markers select _rnd;
_lzMarker = createMarker ["landingZone", _lzPos];
"landingZone" setMarkerText "LZ Test";
"landingZone" setMarkerType "hd_pickup";
"landingZone" setMarkerColor "ColorRed";

 

@Tajin thanks mate, you inspired me :)

Share this post


Link to post
Share on other sites

Well, you could've just updated the marker but that also works.

 

Personally I would've placed all the markers on the map. That is also much easier to edit than generating an array of positions.

Then at the beginning of the map, read those markers into an array, hide them and later simply unhide the ones you need.

 

 

So in the editor just create a marker named "landingZone", configure it the way you want then just copy/paste that marker and place it on all the locations you want.

In your init.sqf use the following code to generate an array of those markers:

 

fnc_findMarkers = {
	_params[
		["_prefix", "", [""]]
	];
	private ["_len"];
	_len = count _prefix;
	allMapMarkers select { (_x select [0, _len]) isEqualTo _prefix }
};

LZmarkers = ["landingZone"] call fnc_findMarkers; // find the markers and save to array
{_x setMarkerType "Empty";} forEach LZmarkers; // hide them all

 

to select an LZ you could then use this:

fnc_selectLZ = {
	_cnt = count LZmarkers;
	if (_cnt isEqualTo 0) exitWith { "" };
	LZmarkers deleteAt floor(random _cnt) // removes the randomly selected marker from the array and returns it as result
};
deleteMarker currentLZ; // delete old LZ marker, or do whatever else you want with it.
currentLZ = call fnc_selectLZ; // select new LZ (automatically gets removed from the array)
currentLZ setMarkerType "hd_pickup"; // make marker visible

 

 

As a result of that you can now freely add or remove LZs by simply adding or removing markers in the editor without having to change the script.

  • Like 3

Share this post


Link to post
Share on other sites

I love it!! :)

 

Thank you for this. This is of course a much smarter way to do things. I have only really just started scripting in anger (and, there's been more anger than script to be honest recently), which is probably evident in my example above, but we all gotta start somewhere I guess haha.

 

This ^^ is amazing, and while I don't claim to fully understand all of it right now (but not far off I think), I'll be dissecting and testing tonight.

 

Nice one! 

:)

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

×