Home   Help Search Login Register  

Author Topic: Determining Distance of a Shot Fired  (Read 1334 times)

0 Members and 1 Guest are viewing this topic.

Offline nEO iNC

  • Contributing Member
  • **
Determining Distance of a Shot Fired
« 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

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Determining Distance of a Shot Fired
« Reply #1 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"}];
« Last Edit: 06 Feb 2008, 21:07:14 by Mandoble »

Offline nEO iNC

  • Contributing Member
  • **
Re: Determining Distance of a Shot Fired
« Reply #2 on: 06 Feb 2008, 11:13:57 »
Nice one Mandoble...!  :good:

Will give that a try later...

Thanks for the quick response...

Offline nEO iNC

  • Contributing Member
  • **
Re: Determining Distance of a Shot Fired
« Reply #3 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..?

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Determining Distance of a Shot Fired
« Reply #4 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:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Determining Distance of a Shot Fired
« Reply #5 on: 06 Feb 2008, 21:07:50 »
Code corrected above, now you'll get a more or less accurate value.

Offline nEO iNC

  • Contributing Member
  • **
Re: Determining Distance of a Shot Fired
« Reply #6 on: 07 Feb 2008, 10:20:38 »
h-, apologies, won't happen again...

Mandoble, thanks again... Appreciated...