Jump to content
Sign in to follow this  
sfc.itzhak

the distance command

Recommended Posts

hi..

i am trying to make an addon that whan it fires the ammunition the script will calculate the distance between the object and the bulit impact point..

i use this script

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_mg = _this select 0;

_ammo = _this select 1;

_round = nearestobject [_this select 0,_this select 4];

~0.1

_dist = _mg distance _round;

_intdest = round _dist

_a1 = (_intdest - _intdest mod 10000) / 10000

_a2 = (_intdest mod 10000 - _intdest mod 1000) / 1000

_a3 = (_intdest mod 1000 - _intdest mod 100) / 100

_a4 = (_intdest mod 100 - _intdest mod 10) / 10

_a5 = (_intdest mod 10)

_str = format["Distance: %1%2%3%4%5", _a1, _a2, _a3, _a4, _a5];

titleText [_str, "PLAIN"];

and sometimes i get numbers that look ok but most of the time i get this value ..

assault_bridge.jpg

dunno why it dose this ..

any idea.

p.s

this is the weapon and ammo sitting if you need it.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">class CfgAmmo

{

class BulletBase;

class LaserRangeFinderAmmo : BulletBase

{

hit = 0;

indirectHit = 0;

indirectHitRange = 0;

model = "";

soundFly[] = {};

hitGround[] = {};

hitMan[] = {};

hitArmor[] = {};

hitBuilding[] = {};

cartridge = "";

cost = 0.0;

deflecting = 0;

visibleFire = 1; // how much is visible when this weapon is fired

audibleFire = 0;

visibleFireTime = 20; // how long is it visible

timeToLive = 20;

typicalSpeed = 10;

};

};

class CfgMagazines

{

/*

class VehicleMagazine;

class 1000Rnd_127x99_M2 : VehicleMagazine

{

scope = public;

displayName = $STR_DN_M2_MG;

ammo = "B_127x99_Ball";

count = 1000;

initSpeed = 930;

};

*/

class CA_Magazine;

class LaserRangeFinderCharge : CA_Magazine

{

scope = public;

displayName = "Laser range finder charges";

ammo = "LaserRangeFinderAmmo";

count = 1000;

initSpeed = 1000;

}

};

class CfgWeapons

{

class MGun;

class LaserRangerFinder : MGun

{

scope = protected;

displayName = "Laser ranger finder";

autoFire = true;

magazines[] = {"LaserRangeFinderCharge"};

sound[] = {};

soundServo[] = {};

reloadTime = 0.11;

magazineReloadTime = 15;

dispersion = 0;

canLock = LockNo;

minRange = 1;

minRangeProbab = 1;

midRange = 5000;

midRangeProbab = 0;

maxRange = 10000;

maxRangeProbab = 0;

aiDispersionCoefY = 7.0;

aiDispersionCoefX = 7.0;

};

};

thanks

sfc.itzhak

Share this post


Link to post
Share on other sites

You're getting that number because when the bullet impacts it is deleted. 0.1 seconds is by no means an accurate way to determine when the bullet impacts anyway. It could take less time than that and when it does impact you'll lose the _round variable since the bullet will no longer exist. You need to use a loop that constantly records the bullet's position and exits when the bullet no longer exists, that will give you the most accurate impact position.

Share this post


Link to post
Share on other sites
You're getting that number because when the bullet impacts it is deleted. 0.1 seconds is by no means an accurate way to determine when the bullet impacts anyway. It could take less time than that and when it does impact you'll lose the _round variable since the bullet will no longer exist. You need to use a loop that constantly records the bullet's position and exits when the bullet no longer exists, that will give you the most accurate impact position.

thanks for the fast reply.

any chance you can give me an example of how to do that?

or even help with this small part?

thanks sfc.itzhak

Share this post


Link to post
Share on other sites

search OFP resources for BulletCam wink_o.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_a1 = (_intdest - _intdest mod 10000) / 10000

_a2 = (_intdest mod 10000 - _intdest mod 1000) / 1000

_a3 = (_intdest mod 1000 - _intdest mod 100) / 100

_a4 = (_intdest mod 100 - _intdest mod 10) / 10

_a5 = (_intdest mod 10)

rofl.gif no rofl.gifrofl.gifrofl.gif

Share this post


Link to post
Share on other sites

you got the answer wink_o.gif you are inventing the bysicle. vad bisycle at the moment wink_o.gif so try search "BulletCam"

Share this post


Link to post
Share on other sites

ok.

i looked in the bulletcam script and this is what i ended up with

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Missile = _this select 0

? isNull _Missile : exit

_Type= typeOf _Missile

#loop

? isNull _Missile : end

_dis2=_Missile distance player

_dis1 = round _dis2

_str = format["%1 meters",(_dis1)]

? ctrlvisible 100 : goto "loop"

#End

titleText [_str, "PLAIN"];

setAccTime 1

exit

but still the maximum distance i get is 80 meters..

any ideas?

Share this post


Link to post
Share on other sites

That's probably because the script does not loop fast enough to get a distance before the bullet impacts after 80m, and you won't get very good results using SQS format anyway (you'd need SQF for more accurate loops).

But for now we'll forget all about scripts, because there is a much better solution for your situation. Don't make your ammo class based on a bullet, instead use something that will let it stick into the ground when it impacts, like a smoke shell or timed grenade (but remove deflection of course). If you do that then you can get the exact position of the round while it's still in the ground where it impacted, without having to worry about very small intervals of time. You'll be able to tell when it has impacted because it will lose all of its velocity.

Share this post


Link to post
Share on other sites
Quote[/b] ]? ctrlvisible 100 : goto "loop"

And what you wanted to do with this command ? what does it mean ?

KyleSarnik

good idea wink_o.gif

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  

×