OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Undeceived on 03 Feb 2009, 16:33:53

Title: Check how much distance was covered
Post by: Undeceived on 03 Feb 2009, 16:33:53
Hi people!

Is there a script that shows you at the final of a mission how much distance was covered by the player in the whole mission? How many kilometers he ran, for example?
And also with an optional graphic that shows a line of the route of the player? You know, like the map view in Counter-Strike when you are a spectator... :D

Thanks for your help!
Title: Re: Check how much distance was covered
Post by: hoz on 03 Feb 2009, 17:01:56
distance (http://www.ofpec.com/COMREF/index.php?action=details&id=107)?  :whistle:  You could use distance and some variable to keep a running tally every few secs.
Title: Re: Check how much distance was covered
Post by: Undeceived on 03 Feb 2009, 17:18:53
Yes, distance certainly is one key command for such a script. The problem is just that I'm such a noob in scripting. :-[
Arrr!! I'll try it out somehow. Thanks, hoz.
Title: Re: Check how much distance was covered
Post by: Mandoble on 03 Feb 2009, 17:33:24
Code: [Select]
// podometer.sqf
private["_pos1", "_pos2", "_unit"];
_unit = _this select 0;

_unit setVariable ["global_dist", 0];
while {alive _unit}
{
   _pos1 = getPos _unit;
   Sleep 2;
   if (alive _unit) then
   {
      _pos2 = getPos _unit;
     _unit setVariable ["global_dist", (_unit getVariable "global_dist")+(_pos1 distance _pos2)];
   };
};

At any time you can check the aproximate total distance checking the internal unit variable "global_dist" in meters.

Code: [Select]
_total_dist = unitname getVariable "global_dist";
Title: Re: Check how much distance was covered
Post by: hoz on 03 Feb 2009, 17:37:36
something like this...

Mando beat me too it. :D
Title: Re: Check how much distance was covered
Post by: Undeceived on 03 Feb 2009, 18:27:59
:D You guys simply rock!!

I'll try it out. Thanks!
Title: Re: Check how much distance was covered
Post by: johnnyboy on 03 Feb 2009, 22:37:48
And for graphically showing path traveled by player, I would modify Mando's code to include an array, and in the loop you add the player's current position to the array.  You would then have a series of positions for which you could create markers, and thus display the path the player had traveled.
Title: Re: Check how much distance was covered
Post by: Worldeater on 03 Feb 2009, 23:27:19
Be aware that this will add 30 markers/min ("sleep 2;"). So after 1h you end up with 1800 markers on your map.
Title: Re: Check how much distance was covered
Post by: johnnyboy on 04 Feb 2009, 17:28:43
Good point.  Probably only want to record a new position if the distance from the last recorded position to the new position is > x meters.  50 or 100 meters between markers might be reasonable...
Title: Re: Check how much distance was covered
Post by: Undeceived on 04 Feb 2009, 20:30:34
Do you mean that the script should only record the positions in the course of the mission and place the markers only at the end, when it is needed?
How can this be done (I mean recording the positions)? I only know how to record positions in camera.sqs with a mouseclick. :P
Title: Re: Check how much distance was covered
Post by: johnnyboy on 04 Feb 2009, 20:45:32
In your init.sqs, initialize an empty global array like this:

Code: [Select]
Pos_tracker_array = [];
The loop that runs during the mission would add player positions via a line like this:

Code: [Select]
Pos_tracker_array = Pos_tracker_array + getpos player;
Each element in the global array would be a position (note that a position is also an array, so the global array is an array of arrays).

Note that you need an if condition around this that tests distance between current player position and last recorded position (as mentioned earlier) to prevent recording too many positions.

On whatever condition you desire, a trigger could fire that would then read that array, and place a marker at every position contained in the array. 

With a little sleep delay in the loop, and forcing to map view, the player could see the markers paint in order (nice little player progress animation effect).  Same sort of technique could be used as a tracking device.  Say a character is being tracked every time he uses his cell phone for instance...