OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: nEO iNC on 06 Feb 2008, 10:50:19

Title: Determining Distance of a Shot Fired
Post by: nEO iNC on 06 Feb 2008, 10:50:19
Hey,

I'm trying to figure out a way of determining the distance a shell flies when fired.  ???

Any help appreciated.

Cheers
Title: Re: Determining Distance of a Shot Fired
Post by: Mandoble on 06 Feb 2008, 11:07:11
This should work:

Code: [Select]
// myshells.sqf
private["_myshell", "_pos_shell"];

_myshell = _this select 0;
if (local (_this select 1)) then
{
   while {!isNull _myshell} do
   {
      _pos_shell = getPos _myshell;
      Sleep 0.001;
   };
   hint format["Distance: %1m", ((_this select 1) distance _pos_shell)];
};


Code: [Select]
//init.sqf
myunit addEventHandler ["Fired", {[(nearestObject[_this select 0, _this select 4]), _this select 0] execVM "myshells.sqf"}];
Title: Re: Determining Distance of a Shot Fired
Post by: nEO iNC on 06 Feb 2008, 11:13:57
Nice one Mandoble...!  :good:

Will give that a try later...

Thanks for the quick response...
Title: Re: Determining Distance of a Shot Fired
Post by: nEO iNC on 06 Feb 2008, 20:26:51
Hey Mandoble,
      Tried your code but it doesn't appear to work...  :(

Just seem to get a 'nothing' value reported when the gun fires.

eg. Distance: SCALARM

Any ideas what might be causing this..?
Title: Re: Determining Distance of a Shot Fired
Post by: h- on 06 Feb 2008, 20:47:05
nEO iNC, do not post consecutively.
A couple fo days should pass first, if you have something to add after a short period of time modify your post instead of replying to yourself.

Quote
Just seem to get a 'nothing' value reported when the gun fires.
You don't get the error message?
Gives me an 'Generic error in expression'
Code: [Select]
  Error Generic error in expression
Suspending not allowed in this context
Error in expression <shell } do
{
_posshell = getPos _shell;
Sleep 0.002;
};
hint format["Distance: %>
  Error position: <Sleep 0.002;
};
:dunno:
Title: Re: Determining Distance of a Shot Fired
Post by: Mandoble on 06 Feb 2008, 21:07:50
Code corrected above, now you'll get a more or less accurate value.
Title: Re: Determining Distance of a Shot Fired
Post by: nEO iNC on 07 Feb 2008, 10:20:38
h-, apologies, won't happen again...

Mandoble, thanks again... Appreciated...