Jump to content
Sign in to follow this  
Meatball0311

Attaching moveable map markers to units?

Recommended Posts

What I am trying to accomplish is having each member of a fireteam to have a movable map marker attached to track movement. I remember in ArmA doing this and actually had it to show a green marker for units that are alive and a red marker for units that are dead.

Any suggestions?

Share this post


Link to post
Share on other sites
while{alive _unit}do{
_marker setMarkerPos (getPos _unit);
_marker setMarkerDir (getDir _unit);
};

Share this post


Link to post
Share on other sites

well that did not exactly help me out with what I was wanting... I am using this and for the time being it is working.

This allows me to place markers on the map and it follows each individual unit around showing their position on the map

#restart

"nameofmarker1" setmarkerpos getpos NAMEOFUNIT1

"nameofmarker2" setmarkerpos getpos NAMEOFUNIT2

"nameofmarker3" setmarkerpos getpos NAMEOFUNIT3

"nameofmarker4" setmarkerpos getpos NAMEOFUNIT4

"nameofmarker5" setmarkerpos getpos NAMEOFUNIT5

"nameofmarker6" setmarkerpos getpos NAMEOFUNIT6

~1

goto "restart"

Share this post


Link to post
Share on other sites

Oh sorry I must have missed the second half of your question:

_unit = _this select 0;
_marker = _this select 1;

_marker setMarkerColor "ColorGreen";

while{alive _unit}do{
 _marker setMarkerPos (getPos _unit);
 _marker setMarkerDir (getDir _unit);
};

_marker setMarkerColor "ColorRed"

Obviously you have to pass [unit,marker] as arguments. Also be sure to execute it on all clients if you're using it in MP so that everyone can see the markers update.

Share this post


Link to post
Share on other sites

If you want to use it for respawning units, give this one a try:

_temp = _this select 0;
_varname = vehicleVarName _temp;
_unit = objnull;


createMarkerLocal [_varname, [0,0]];
_varname setMarkerShape "ICON";
_varname setMarkerColor "ColorBlack";
_varname setMarkerSize [1,1];
_varname setMarkerType "Arrow";

while {true} do {
waitUntil {
	call compile format ["_unit = %1",_varname];
	alive _unit;
};

while {alive _unit} do {
	if (side _unit == west) then {
		_varname setMarkerColor "ColorBlue";
	};
	if (side _unit == east) then {
		_varname setMarkerColor "ColorRed";
	};
	_varname setMarkerDir getDir _unit;
	_varname setMarkerPos getPos _unit;

	sleep 0.5;
};
_varname setMarkerColor "ColorBlack";
sleep 5;
};

nul=[this] execVM "marker.sqf";

Important: Any soldier you use this on, has to have a varname.

It's based on an script I used for giving orders to respawning AI soldiers, only just changed it (it's not tested).

Share this post


Link to post
Share on other sites

I modified your code Tajin... just for fun. :j:

_temp = _this select 0;
_varname = vehicleVarName _temp;
_unit = objnull;

_colorFriendly = "ColorGreen";
_colorDead = "ColorBlack";
_shapeAlive = "Arrow";
_shapeDead = "Marker";

createMarkerLocal [_varname, [0,0]];
_varname setMarkerShape "ICON";
_varname setMarkerColor "ColorBlack";
_varname setMarkerSize [1,1];
_varname setMarkerType "Empty";

if(side _unit == side player)then{

while {true} do {
   waitUntil {
       call compile format ["_unit = %1",_varname];
       alive _unit;
   };

   while {alive _unit} do {
       _varname setMarkerColor _colorFriendly;
       _varname setMarkerType _shapeAlive;

       _varname setMarkerDir getDir _unit;
       _varname setMarkerPos getPos _unit;

       sleep 0.5;
   };
   _varname setMarkerColor _colorDead;
   _varname setMarkerType _shapeDead;
   sleep 5;
};  

};

Share this post


Link to post
Share on other sites

Thanks for all of the suggestions, but I have found that this gives me at this point what I am looking for. To sum it up I am eventually wanting to have a "Dot" shaped marker represent my unit(s) location in the map screen. The "Dot" marker will be green as long as the unit is alive and will turn red when the unit is dead. I am not the best at scripting so I guess I am taking baby steps and this is what I got so far...

;this will place a moveable green "Dot" marker that will represent the units position on the map

#top

createMarker ["markername", getPos UNITNAME]

"markername" setMarkerPos getpos UNITNAME

"markername" setMarkerColor "ColorGreen"

"markername" setMarkerType "Dot"

"markername" setMarkerSize [0.3, 0.3]

goto "top"

A few questions that I have:

1. I notice that you are using "sqf" scripts.. is that better than using "sqs" scripts?

2. My next step in the script will be to set it up that if the unit is "alive" for the marker to be green, but if the unit is "dead" the marker will turn red... any suggestions on how to do that?

3. Also can someone please explain what " this select 0 " and so on " this select 1 " means?

Share this post


Link to post
Share on other sites
1. I notice that you are using "sqf" scripts.. is that better than using "sqs" scripts?

Yes. ;)

2. My next step in the script will be to set it up that if the unit is "alive" for the marker to be green, but if the unit is "dead" the marker will turn red... any suggestions on how to do that?

Yes, look at the examples me and Tajin posted.

3. Also can someone please explain what " this select 0 " and so on " this select 1 " means?

_this is a reserved local variable that contains the arguments passed into the script when it is called (via exec, execVM, call, or spawn). Since it is usually passed as an array (as to allow for multiple arguments), we use the select command to reference the individual elements of it. So, for example, passing [player,"PlayerMarker"] into the script, _this select 0 would evaluate to player, and _this select 1 would evaluate to "PlayerMarker".

Share this post


Link to post
Share on other sites

Thanks for the reply Big Dawg!

1. So what is the difference between "sqs" and sqf"?

2. I am looking at your examples but it just isnt making sense to me... this is what I have been trying to do:

_unit = _this select 0

#top

hint "THIS IS A TEST"

if (alive _unit) then goto "alive"

if (!alive _unit) then goto "dead"

~1

goto "top"

#alive

createMarker ["alivemarkername", getPos UNITNAME]

"alivemarkername" setMarkerPos getpos UNITNAME

"alivemarkername" setMarkerColor "ColorGreen"

"alivemarkername" setMarkerType "Dot"

"alivemarkername" setMarkerSize [0.3, 0.3]

goto "top"

#dead

deleteMarker "alivemarkername"

~1

createMarker ["deadmarkername", getPos Test]

"deadmarkername" setMarkerPos getpos Test

"deadmarkername" setMarkerColor "ColorRed"

"deadmarkername" setMarkerType "Dot"

"deadmarkername" setMarkerSize [0.3, 0.3]

goto "top"

I am using the hint "THIS IS A TEST" to test if I am using the right commands. The script is continually looping back to "top" and does continue on to "alive" giving me green "Dot" moveable markers on game map. However, when I test the command to check if the _unit is alive - if (!alive _unit) then goto "dead" - nothing happens when the unit dies... it just stays green.

Share this post


Link to post
Share on other sites

SQF is newer than SQS, more flexible and easier to handle.

Simply put, if you're already learning to script, then you're better of learning SQF in the first place.

I'll explain a bit of it:

    while {alive _unit} do {
       if (side _unit == west) then {
           _varname setMarkerColor "ColorBlue";
       };
       if (side _unit == east) then {
           _varname setMarkerColor "ColorRed";
       };
       _varname setMarkerDir getDir _unit;
       _varname setMarkerPos getPos _unit;

       sleep 0.5;
   };

this part is solely responsible for updating the marker and loops as long as the unit is alive. If the unit is dead, the script continues to this step:

_varname setMarkerColor "ColorBlack";

Which sets the color to black, indicating that the unit is dead. There is really no point in updating the position of the marker in that case. Dead units normally don't move.

After that, the script waits for the unit to respawn and repeats the whole thing.

Share this post


Link to post
Share on other sites

I tried your sqf function script and it is not working... dont know if I am executing it right or not but I aint getting nothing.

I am getting the script down, I am just not getting or understand how to command the script to when the unit is dead to go to the #dead part of the script...

;this will place a moveable green "Dot" marker that will represent the units position on the map

_unit = _this select 0

#alive

while{alive _unit}do{

createMarker ["FR1marker", getPos FR1]

"FR1marker" setMarkerPos getpos FR1

"FR1marker" setMarkerColor "ColorGreen"

"FR1marker" setMarkerType "Dot"

"FR1marker" setMarkerSize [0.3, 0.3]

createMarker ["FR2marker", getPos FRC2]

"FR2marker" setMarkerPos getpos FRC2

"FR2marker" setMarkerColor "ColorGreen"

"FR2marker" setMarkerType "Dot"

"FR2marker" setMarkerSize [0.3, 0.3]

createMarker ["FR3marker", getPos FR3]

"FR3marker" setMarkerPos getpos FR3

"FR3marker" setMarkerColor "ColorGreen"

"FR3marker" setMarkerType "Dot"

"FR3marker" setMarkerSize [0.3, 0.3]

createMarker ["FR4marker", getPos FR4]

"FR4marker" setMarkerPos getpos FR4

"FR4marker" setMarkerColor "ColorGreen"

"FR4marker" setMarkerType "Dot"

"FR4marker" setMarkerSize [0.3, 0.3]

createMarker ["FR5marker", getPos FR5]

"FR5marker" setMarkerPos getpos FR5

"FR5marker" setMarkerColor "ColorGreen"

"FR5marker" setMarkerType "Dot"

"FR5marker" setMarkerSize [0.3, 0.3]

createMarker ["FR6marker", getPos FR6]

"FR6marker" setMarkerPos getpos FR6

"FR6marker" setMarkerColor "ColorGreen"

"FR6marker" setMarkerType "Dot"

"FR6marker" setMarkerSize [0.3, 0.3]

createMarker ["testmarker", getPos Test]

"testmarker" setMarkerPos getpos Test

"testmarker" setMarkerColor "ColorGreen"

"testmarker" setMarkerType "Dot"

"testmarker" setMarkerSize [0.3, 0.3]

}

while {!alive _unit}do{goto "dead"}

goto "alive"

#dead

I know that I am probably going the "long" way in trying to accomplish this, but I have to take simple minded steps while I am in this learning process

Edited by Meatball0311

Share this post


Link to post
Share on other sites

Please don't try to mix up SQS code with SQF code. It won't work ^^

Have a look at some background information at the biki.:

http://community.bistudio.com/wiki/sqf

It's good that you're trying to learn but aside from that, I'm pretty sure that the scripts dawg and me posted are functional, give them a try.

Share this post


Link to post
Share on other sites

I am sure they are, but how do you exec them? Do I have to place [] execVM "script.sqf" into the init of all the units I want to have markers? or do I have to place it in the init.sqs?

Share this post


Link to post
Share on other sites

Can I slip in here with a related question?

What if I want these markers to be visible to one side only (i.e. only BLUFOR, in multiplayer).

Share this post


Link to post
Share on other sites
Can I slip in here with a related question?

What if I want these markers to be visible to one side only (i.e. only BLUFOR, in multiplayer).

Check my modified version of Tajin's script. I added a bit to make the markers only visible to players on the same side.

Share this post


Link to post
Share on other sites

Ok I am not trying to make any type of scripts for multiplayer so I dont know if that may be the problem, but I am using the scripts that you have recommended and nothing is happening.

This is what I am doing:

1. I have named to units "test" "test1"

2. I made a init.sqf and put into it

test execVM "markerfunction.sqf";

test1 execVM "markerfunction.sqf";

3. I am using this sqf named " markerfunction.sqf"

_temp = _this select 0;

_varname = vehicleVarName _temp;

_unit = objnull;

_colorFriendly = "ColorGreen";

_colorDead = "ColorBlack";

_shapeAlive = "Arrow";

_shapeDead = "Marker";

createMarkerLocal [_varname, [0,0]];

_varname setMarkerShape "ICON";

_varname setMarkerColor "ColorBlack";

_varname setMarkerSize [1,1];

_varname setMarkerType "Empty";

if(side _unit == side player)then{

while {true} do {

waitUntil {

call compile format ["_unit = %1",_varname];

alive _unit;

};

while {alive _unit} do {

_varname setMarkerColor _colorFriendly;

_varname setMarkerType _shapeAlive;

_varname setMarkerDir getDir _unit;

_varname setMarkerPos getPos _unit;

sleep 0.5;

};

_varname setMarkerColor _colorDead;

_varname setMarkerType _shapeDead;

sleep 5;

};

4. I load mission in the editor and preview and nothing is displayed on game map???!!???

Am I executing the script right? and how do I do that? Please explain potato head style!

Share this post


Link to post
Share on other sites

Dude, I am sorry but "NO JOY". It still isnt working... it is doing nothing.

A little fyi I am not having any type of respawn in my mission.

Share this post


Link to post
Share on other sites

Very well, then this script should do just fine for you:

_unit = _this select 0;
_marker = _this select 1;

_marker setMarkerColor "ColorGreen";

while{alive _unit}do{
 _marker setMarkerPos (getPos _unit);
 _marker setMarkerDir (getDir _unit);
};

_marker setMarkerColor "ColorRed"

Called with:

[unit,"markername"] execVM "script.sqf"

You have to actually place the marker on the map for this, and pass it to the script.

Share this post


Link to post
Share on other sites

For the sake of your CPU you should add a pause(sleep) in that script.

Otherwise the game engine will try to update the marker as fast as it could, this is generally not needed.

as follows

...
while{alive _unit}do{
 _marker setMarkerPos (getPos _unit);
 _marker setMarkerDir (getDir _unit);
 [color=Blue]sleep 0.1;[/color] [color=SeaGreen]//Or what you feel appropriate (time is in seconds)[/color]
};
...

Actually when I come to think of it one of my scripts stalled Arma when I forgot the sleep.

Dunno if that was because i used "spawn" instead of "execVM"

Share this post


Link to post
Share on other sites

It depends on what you are doing in the loop (and how intensive it is). You're right though, it's probably a good idea to put at least a small sleep in it.

Share this post


Link to post
Share on other sites

hallelujah!!! hallelujah!!! hallelujah!! it worked..... thanks for your troubles!

---------- Post added at 09:27 AM ---------- Previous post was at 09:25 AM ----------

so is " sleep " just like " ~ " ??? but for sqf? So is there new commands depending on if you are using sqs. or sqf?

Share this post


Link to post
Share on other sites

I tried to search this, but no luck, or i missed it, or just didn't type in the right search words (multiplayer marker)

so, Question:

Could this marker script made to change the marker color depending the state of a task?

I need something to update marker colors/text for other players in COOP.

Task1 MARKER is named "obj1" andthe MARKER color is RED. Once task1 is completed, and it turns to green for me, BUT it doesn't turn to green on other players, and i don't know if the text in the marker will change for other players if i wish to change it.

Suggestions? =)

Edited by Carpaazi

Share this post


Link to post
Share on other sites

nul=[this] execVM "marker.sqf";

Important: Any soldier you use this on' date=' has to have a varname.

It's based on an script I used for giving orders to respawning AI soldiers, only just changed it (it's not tested).[/quote']

how do you set a varname??

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  

×