Centerbe
Offline
|
 |
« on: 14 Feb 2009, 12:25:32 » |
|
Hi, im newbie in scripting how i can show the distance from player to target with sqf? i see in some player view arma just show a cursor and distances in meters... Code: _range = target distance player; //?  hint _range; thanks?
|
|
|
|
« Last Edit: 15 Feb 2009, 01:08:06 by Centerbe »
|
Logged
|
|
|
|
|
Worldeater
|
 |
« Reply #1 on: 14 Feb 2009, 12:43:40 » |
|
Welcome!  What do you mean with "target"? The object you are looking at? Or maybe the object your barrel is pointing at? Or your next waypoint? Oh, and please, please with a cherry on top, write a proper topic description next time. 
|
|
|
|
|
Logged
|
try { return true; } finally { return false; }
|
|
|
|
|
|
Mandoble
|
 |
« Reply #3 on: 14 Feb 2009, 14:09:27 » |
|
There is noly one point missing there as ArmA doesnt have any command to give you your current locked on target.
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Mandoble
|
 |
« Reply #5 on: 14 Feb 2009, 14:31:23 » |
|
There is not such a thing as "object observed or pointed at" in ArmA returned by any command.
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Mandoble
|
 |
« Reply #7 on: 14 Feb 2009, 14:46:29 » |
|
Which is the case you want to solve? an AA unit vs a plane? A soldier vs a soldier? If the former, then you have an option as there will be unlikely many planes in front of you gun. You may get your weapon Direction (the weapon of the vehicle), and then look for the closest air unit. Then get the angle between that unit and your vehicle position and calculate the difference between that angle and your weapon direction. If the difference is less than 20 degrees, you may "conclude" that, if any, this plane should be the target.
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Mandoble
|
 |
« Reply #9 on: 14 Feb 2009, 15:51:15 » |
|
Might be nearTargets is not the best solution, you may try: private["_ship", "_trigger", "_planes"]; _ship = _this select 0; _maxrange = 2000; _trigger = createTrigger ["EmptyDetector", getPos _ship]; _trigger setTriggerActivation ["ANY", "PRESENT", false]; _trigger setTriggerArea [_maxrange, _maxrange, 0, false]; _trigger setTriggerType "NONE"; _trigger setTriggerStatements ["this", "", ""]; _trigger setTriggerTimeout [0, 0, 0, false ]; Sleep 1; while {true} do { _trigger setPos getPos _ship; _planes = []; { if (_x isKindOf "Air") then { if (isEngineOn _x) then { _planes = _planes + [_x]; }; }; } forEach list _trigger;
if (count _planes > 0) then { // Check potential targets here }; Sleep 0.5; };
|
|
|
|
|
Logged
|
|
|
|
Centerbe
Offline
|
 |
« Reply #10 on: 14 Feb 2009, 17:46:08 » |
|
Im sorry Mandoble im feeling me very stupid ask to you this... but if _x is the plane ID, i need measures the distance from _ship to _x private["_ship", "_trigger", "_planes"]; _ship = _this select 0; _maxrange = 2000; _trigger = createTrigger ["EmptyDetector", getPos _ship]; _trigger setTriggerActivation ["ANY", "PRESENT", false]; _trigger setTriggerArea [_maxrange, _maxrange, 0, false]; _trigger setTriggerType "NONE"; _trigger setTriggerStatements ["this", "", ""]; _trigger setTriggerTimeout [0, 0, 0, false ]; Sleep 1; while {true} do { _trigger setPos getPos _ship; _planes = []; { if (_x isKindOf "Air") then { if (isEngineOn _x) then { _planes = _planes + [_x]; }; }; } forEach list _trigger;
if (count _planes > 0) then { if (side _planes == east) then // if the planes is a enemy { _dist = _planes distance _trigger; hint format ["%1", _dist]; // show the distance value }; }; Sleep 0.5; };
I hope this is correct....
|
|
|
|
|
Logged
|
|
|
|
|
Mandoble
|
 |
« Reply #11 on: 14 Feb 2009, 17:55:09 » |
|
private["_ship", "_trigger", "_planes", "_msg", "_dist"]; _ship = _this select 0; _maxrange = 2000; _trigger = createTrigger ["EmptyDetector", getPos _ship]; _trigger setTriggerActivation ["ANY", "PRESENT", false]; _trigger setTriggerArea [_maxrange, _maxrange, 0, false]; _trigger setTriggerType "NONE"; _trigger setTriggerStatements ["this", "", ""]; _trigger setTriggerTimeout [0, 0, 0, false ]; Sleep 1; while {true} do { _trigger setPos getPos _ship; _planes = []; { if (_x isKindOf "Air") then { if ((isEngineOn _x) && (side _x == east)) then { _planes = _planes + [_x]; }; }; } forEach list _trigger;
if (count _planes > 0) then { _msg = ""; { _dist = _x distance _ship; _msg = _msg + format["Target:%1 - Range: %2\n", _x, _dist]; } forEach _planes; hint _msg; // show the distances and targets values }; Sleep 0.5; };
|
|
|
|
|
Logged
|
|
|
|
Centerbe
Offline
|
 |
« Reply #12 on: 14 Feb 2009, 18:13:23 » |
|
great.... it work fine....  thanks very much i will study the code for progress.... thanks very much mandoble.
|
|
|
|
|
Logged
|
|
|
|
|
Mandoble
|
 |
« Reply #13 on: 14 Feb 2009, 18:31:40 » |
|
You are still missing a point there, to make sure that the plane is more or less in front of your weapon.
|
|
|
|
|
Logged
|
|
|
|
|
|
|