Warning: include(/var/www/html/forum/Sources/../../../includes/depot_files/OFPEC_get_header_image.inc.php): failed to open stream: No such file or directory in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 146

Warning: include(): Failed opening '/var/www/html/forum/Sources/../../../includes/depot_files/OFPEC_get_header_image.inc.php' for inclusion (include_path='.:/usr/local/lib/php') in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 146

Notice: Undefined index: OFPEC in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152

Notice: Trying to access array offset on value of type null in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152

Notice: Trying to access array offset on value of type null in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152
    Home   Help Login Register  

Author Topic: LaserDesignator in MP mission  (Read 3212 times)

0 Members and 1 Guest are viewing this topic.

Offline Goullou

  • Members
  • *
LaserDesignator in MP mission
« on: 18 Dec 2007, 10:20:26 »
Hi all !

I'm working on a script for a coop mission where ground units help AV8B2 pilots to do their job.
All ground units have got a Laserdesignator.
What i'm trying to do is to give points to the player who designated the target.

If i check the target with:
Code: [Select]
_pos = position _target;
_laserspot = (nearestObject [_pos, "LaserTarget"]);
... i get something which could be used as an ID.

But i don't know how to know who is making the laser designation.
I've tried with an addEventHandler "fired" on the players to get something to associate with this ID but the laserdesignator doesn't work like any other weapon and doesn't return anything.

Any idea should be welcome.
Goullou
Si vis pacem, para bellum.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: LaserDesignator in MP mission
« Reply #1 on: 18 Dec 2007, 14:09:36 »
Everyone is going to have an LD there? If not, you may check who has them and then check their weaponDirection with the position where the ldtarget is found, if deviation between weaponDirection and the LDtarget is minimal, then that unit is the "owner" of the LDtarget.

Offline Goullou

  • Members
  • *
Re: LaserDesignator in MP mission
« Reply #2 on: 19 Dec 2007, 11:41:49 »
Everyone is going to have an LD there?

Not everyone but a lot of them.

Quote
If not, you may check who has them and then check their weaponDirection with the position where the ldtarget is found, if deviation between weaponDirection and the LDtarget is minimal, then that unit is the "owner" of the LDtarget.

How to know who have the LD in hand?
I suppose the direction of the LaserDesignator (weapon) is the same as the player direction... isn't it ?
I have to check if the LaserTarget has a direction as well :scratch: if it's the case perhaps i can find what player has exactly the same ...
Otherwize i'll try to find a relation between the player azimut and the Lasertarget position.

If BIS had included any kind of information about the unit making the Lasertarget in its definition would be better  >:(

Thanks Mandoble for this.

Any other idea still welcome.
« Last Edit: 19 Dec 2007, 11:48:21 by Goullou »
Si vis pacem, para bellum.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: LaserDesignator in MP mission
« Reply #3 on: 19 Dec 2007, 11:57:01 »
Try this:
Mando My Weapon

And no, weapon direction is not unit direction. Check weaponDirection command. It returns an array similar to vectorDir [-1 to 1, -1 to 1, -1 to 1]. For your particular case, you may calculate the distance between the unit and LT, and using it and weaponDirection, calculate where the LT of that unit should be: _poslt = [(_weapon_dir select 0)*_dist,(_weapon_dir select 1)*_dist, (_weapon_dir select 2)*_dist], then calculate the distance between this position and the LT and if smaller than 5m, then you may conclude that this unit is the owner of the LT.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: LaserDesignator in MP mission
« Reply #4 on: 19 Dec 2007, 13:56:19 »
If you don't want to do a lot of coding, you could always just use SPON Rangefinder, which deals with this for you. Look in the init.sqf in the demo to see how to be informed when a target is painted, or look at this example:
Code: (init.sqf) [Select]
// After SPON Core and SPON Rangefinder have been initialised, add:
_targetFoundHandler =
{
_target = _this select 0;
        _firer = _this select 1;
        _targetPos = _this select 2;

hint format ["%1 painted a target", name _firer];

        // Must spawn if you want to spend time (sleep/waituntil) inside a SPON event handler.
[_target] spawn
{
            _target = _this select 0;

    waitUntil { isNull _target; };

    hint "target lost";
};
};

["SPON_laserTargetFound", _targetFoundHandler] call SPON_addEventHandler;

Alternatively, you could check a variable on an existing laser target object to see who is "firing" it:
Code: (Assuming that _target represents a laser designator target that you have found) [Select]
_firer = _target getVariable "SPON_laserTargetOwner";
« Last Edit: 19 Dec 2007, 13:58:07 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Goullou

  • Members
  • *
Re: LaserDesignator in MP mission
« Reply #5 on: 21 Dec 2007, 17:44:21 »
Thanks for all of that.

But it remains complicated solutions.

Otherwise, perhaps i found a good way to do it.
Here are some news:
1) I found the LaserTarget object (the spot) has a direction (0 to 360°).

2) Using a part of the math given by Mandoble about the weaponDirection command from his "mando_my_weapon" function:
Code: [Select]
_dirweap = ((_unit weaponDirection _weap) select 0) atan2 ((_unit weaponDirection _weap) select 1);Which converts the tridimentionnal values of the command to angles (negative for the West, positive for the East).
Where i did:
Code: [Select]
_unit = player;
_weap = "LaserDesignator";
_dirweap = ((_unit weaponDirection _weap) select 0) atan2 ((_unit weaponDirection _weap) select 1);
if (_dirweap < 0) then
{
_dirweap = (360 + _dirweap);
};
if (_dirweap == 360) then
{
_dirweap = 0;
};

3) The LaserTarget object (the spot) has exactly the same direction as the LaserDesignator which make it.

Then the player who has got a designator where the direction is the same of the spot direction is the one who get points.

Otherwise i check the animation of the player this to avoid all players to run a script:
Code: [Select]
_allAnim = ["AwopPercMstpSoptWbinDnon_rfl","AwopPercMstpSoptWbinDnon_pst","AwopPercMstpSoptWbinDnon_non","AwopPknlMstpSoptWbinDnon_rfl","AwopPknlMstpSoptWbinDnon_pst","AwopPknlMstpSoptWbinDnon_lnr","AwopPpneMstpSoptWbinDnon_rfl","AwopPpneMstpSoptWbinDnon_pst","AwopPpneMstpSoptWbinDnon_non"];
_anim = animationState _unit;
if (_anim in _allAnim) then
{
for [{_loop ...................... etc ...
These are the 9 possible animations of a unit using both LaserDesignator and Binocular.

I actualy have a beta script which needs to be tested on a server.
I'll keep you informed about it...

Thanks again.

Goullou
Si vis pacem, para bellum.