Results 1 to 3 of 3

Thread: Issue with using "getDir" on mountable weapons

  1. #1

    Issue with using "getDir" on mountable weapons

    I am trying to capture the direction(azimuth) of the weapon a player is mounted to, such as an M2 machine gun, TOW tripod, mortar, etc.

    The problem is that as soon as I mount the weapon, the "getDir" command seems to fail/stop working. Here is my code:

    Code:
    _RunLoop = true;
    While {_RunLoop} do 
    {
    _deg = getDir (vehicle player);
    hintSilent format ["Degrees: %1", _deg];
    };
    Does anyone know what is wrong? Thanks!
    CRcti Proman: http://forums.bistudio.com/showthrea...4-CRcti-Proman

    I defeated the Mayan Doomsday Apocalypse.... you're welcome.

  2. #2
    PHP Code:
    // find array of weapons in the static gun

    _weapons getArray (configFile >> "CfgVehicles" >> typeOf (vehicle player) >> "Turrets" >> "MainTurret" >> "weapons");

    // select main gun

    _weap _weapons select 0;

    // return direction in x,y,z format

    _dir_array = (vehicle playerweaponDirection _weap;

    // convert to degrees

    _dir_degrees = (_dir_array select 0atan2 (_dir_array select 1);

    // convert to 360 deg format

    if (_dir_degrees 0then {_new_degrees = (_dir_degrees 360)} else {_new_degrees _dir_degrees};

    // test with sidechat

    player sideChat format["new deg %1"_new_degrees]; 
    Hackintosh Windows 7/Mountain Lion. Intel i7-920 @3.8 Ghz.
    Gigabyte GA-EX58-UD5 Rev1. Palit GTX 680 4GB.
    6Gb DDR3 RAM. Corsair 650W PSU.

  3. #3
    Thanks Das Attorney!

    Your code works great, except that 180 degrees to 360 was still displaying a negative number, so I just changed your code:

    Code:
    // convert to 360 deg format 
    
    if (_dir_degrees < 0) then {_new_degrees = (_dir_degrees + 360)} else {_new_degrees = _dir_degrees};
    To this:

    Code:
    If (_dir_degrees < 0) Then 
       {
    	_dir_degrees = _dir_degrees + 360;
       };
    Now it works perfect. Danke schön!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •