Home   Help Search Login Register  

Author Topic: Check how much distance was covered  (Read 1862 times)

0 Members and 2 Guests are viewing this topic.

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
Check how much distance was covered
« 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!
« Last Edit: 03 Feb 2009, 16:39:50 by Undeceived »
Current project: Black Lands (Arma 3)

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: Check how much distance was covered
« Reply #1 on: 03 Feb 2009, 17:01:56 »
distance:whistle:  You could use distance and some variable to keep a running tally every few secs.
Xbox Rocks

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
Re: Check how much distance was covered
« Reply #2 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.
Current project: Black Lands (Arma 3)

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Check how much distance was covered
« Reply #3 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";
« Last Edit: 03 Feb 2009, 17:35:11 by Mandoble »

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: Check how much distance was covered
« Reply #4 on: 03 Feb 2009, 17:37:36 »
something like this...

Mando beat me too it. :D
Xbox Rocks

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
Re: Check how much distance was covered
« Reply #5 on: 03 Feb 2009, 18:27:59 »
:D You guys simply rock!!

I'll try it out. Thanks!
Current project: Black Lands (Arma 3)

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re: Check how much distance was covered
« Reply #6 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.
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Check how much distance was covered
« Reply #7 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.
« Last Edit: 03 Feb 2009, 23:34:40 by Worldeater »
try { return true; } finally { return false; }

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re: Check how much distance was covered
« Reply #8 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...
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
Re: Check how much distance was covered
« Reply #9 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
Current project: Black Lands (Arma 3)

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re: Check how much distance was covered
« Reply #10 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...
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...