Forum Jump :

Author Message


Posts: 89
Rank:


Level: Member

Country: in
Location:
Occupation:
Age:
In-game name:

 
#195670 Posted at 2017-01-05 19:10        
     
I want to select individual units by pressing F2,F3,F4 keys etc, the code Groupselectedunits works but if i check the units status or if the unit is in vehicle in script it gives error - "Type array,Expected object". While without the units check the script works.

my example script below-

I have placed 3 ai units on map with player as leader of group and helipad h1.
Activate in radio alpha- null = [] execVM "select.sqf";

select.sqf
if (!isServer) exitWith {};
sleep 1;
disableSerialization;
waituntil {!isnull(findDisplay 46)};
_display = findDisplay 46;
_display displayaddEventHandler ["KeyDown","nul = _this execVM ""move.sqf"""];

hintsilent "script activated!";

move.sqf
private['_handled'];
_handled = false;

sleep 0.1;
switch (_this select 1) do
             {
                //Key f2
        case 60: {
            unit2 = groupSelectedUnits player;
            hint "Key F2 selected!";
            if (!alive unit2) exitwith {hintsilent "unit not available!";};
            if (vehicle unit2!= unit2) exitwith {hintsilent "Selected unit cannot move while in vehicle!,call script again!"}; 
            unit2 domove getpos h1;
            //This will ensure only one unit is selected at a time.
            (findDisplay 46) displayRemoveAllEventHandlers "KeyDown"; 
            
        };
                
                //Key f3
        case 61: {
            hint "Key F3 selected!";
            unit3 = groupSelectedUnits player;
            unit3 domove getpos h1;
            sleep 3;
            //This will ensure only one unit is selected at a time.
            (findDisplay 46) displayRemoveAllEventHandlers "KeyDown";
            
        };
                //Key f4
        case 62: {
            hint "Key F4 selected!";
            unit4 = groupSelectedUnits player;
            unit4 domove getpos h1;
            sleep 3;
            //This will ensure only one unit is selected at a time.
            (findDisplay 46) displayRemoveAllEventHandlers "KeyDown"; 
            
        };
};
_handled;