Forum Jump :

Author Message


Posts: 87
Rank:


Level: Member

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

 
#1 Posted at 2016-11-30 21:00        
     
How should one select individual units in player group via keypress (e.g F2,F3...F12) in a script with this - https://community.bistudio.com/wiki/displayAddEventHandler and then the selected unit will then run a script code or sqf.

This post was edited by warbird (2017-01-03 18:06, 344 days ago)


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 20
In-game name: Wak

 
#2 Posted at 2016-11-30 22:22        
     
You don't need to add a keybind to the function keys, the groupSelectedUnits command returns those selected units.

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Advertisement


Author Message


Posts: 87
Rank:


Level: Member

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

 
#3 Posted at 2017-01-03 18:05        
     
The groupselectedunits returns multiple AI units in array so how should one select individual units using this - https://community.bistudio.com/wiki/groupSelectUnit command in a script? Can anyone post a example script for both GroupselectedUnits and groupselectUnit?


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 20
In-game name: Wak

 
#4 Posted at 2017-01-04 13:47        
     
Do you want to select some units for the player, or get the units that the player has selected? You said a script will run with the selected units so I assumed it was the latter.

private "_array";
_array = groupSelectedUnits player; // Will return units selected with F2, F3...

// Will select the first two units, highlighting them in the group bar
player groupSelectUnit [(units player) select 1, true];
player groupSelectUnit [(units player) select 2, true];

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Author Message


Posts: 87
Rank:


Level: Member

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

 
#5 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;


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 57
In-game name: Kobayashi Maru

 
#6 Posted at 2017-01-05 23:26        
     
Why all that "mess"?
I'm not sure you have to mix checks for key pressed + unit selected !

[] spawn {
  while {true} do {
   sleep 0.5;
   if (unit1 in groupSelectedUnits unit1) then {
     waitUntil { !(unit1 in groupSelectedUnits unit1) ); // optional
     unit1 doMove getPos h1;
   };
  };
};

If you want only one unit selected as condition:
[unit1] isEqualTo groupSelectedUnits unit1


or even:
in radio alpha:
unit1 doMove getpos h1

:-|

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 20
In-game name: Wak

 
#7 Posted at 2017-01-06 04:00        
     
Look at the wiki page, groupSelectedUnits returns an array; that means a list of units. When you write `unit2 = groupSelectedUnits player;` or `unit3 = groupSelectedUnits player;`, what you're getting is actually something like this:
unit2 = [unit1, unit2, unit3];
unit3 = [unit1, unit2, unit3];

That's why you get an error that says "Type array,Expected object", because you're trying to use an array instead of a unit. You'd need to use the select command to pick a specific unit from that array, or use a forEach loop to do something with all the objects in the array.

https://community.bistudio.com/wiki/Array

Hope it's clear enough now, you don't really need to something specific for each key press, you just have to make sure it's an 'FX' key, then use groupSelectedUnits.

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Author Message


Posts: 87
Rank:


Level: Member

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

 
#8 Posted at 2017-02-06 02:25        
     
i have corrected the errors in previous post now the script is able to select single units with keypress.

To use this script press windows left key once and then a select any single unit by pressing any F2,F3...F12 within 5 seconds.Once "unit selected" hint appears a visual marker will appear and will be placed at any structure height/level near the player's position, the selected unit will then move to the visual markers position.This script allows units in group to move to any buildings floor levels or inside structures.You can also use classname "Sign_arrow_down_large_EP1" as markericon in selectunit.sqf.

create init.sqf,selectunit.sqf,setunitpos.sqf and place in mission folder-

init.sqf
sleep 1;
disableSerialization;
_display = findDisplay 46;
_display displaySetEventHandler ["KeyDown","_nil = _this execVM ""selectUnit.sqf"""];

titleText ["Press windows Left key once to activate script","plain down"];

selectunit.sqf

private['_handled'];
_handled = false;

sleep 0.1;
switch (_this select 1) do
{
// KEY windows Left 
case 219: 
{
markerIcon = "Sign_sphere100cm_EP1" createVehicle [0,0,0];
_handled = true;
titleText ["Select any unit (F2,F3,F4..F12) once & point cursor towards position to move unit to position!","plain down"];

sleep 1;
hintsilent "select any single unit in 5 seconds!";

sleep 1;
hintsilent "select unit in 5";
sleep 1;
hintsilent "select unit in 4";
sleep 1;
hintsilent "select unit in 3";
sleep 1;
hintsilent "select unit in 2";
sleep 1;
hintsilent "select unit in 1";
sleep 1;

SquadUnits = groupSelectedUnits player;
unit = Squadunits select 0; 

sleep 1;//Exit script if selected AI is in vehicle.
if (vehicle unit!= unit) exitwith {hintsilent "Selected unit cannot move while in vehicle!,call script again!";deletevehicle markerIcon;};

sleep 1;//Exit script if no AI unit is selected.
if (isNil "unit") exitwith {hintsilent "No unit selected,call script again!";deletevehicle markerIcon;};

hintsilent "unit selected!";

moveai = [markerIcon,unit] execVM "setunitpos.sqf";
waituntil {scriptdone moveai};

hintsilent "Select other units!";
};
};
_handled;


setunitpos.sqf
_marker = _this select 0;
_selectedunit = _this select 1;

sleep 1;
_marker attachTO [player,[0,3,1.3]];
 
sleep 5;
_marker setvelocity [0,0,0];
detach _marker;
_marker setPosATL getPosATL player;
_marker setposATL (player modelToWorld [0,3,0]);

sleep 0.1;//order AI to move to marker.
_selectedunit lookat _marker;
_selectedunit dowatch _marker;
_selectedunit domove getposATL _marker;
_selectedunit setspeedmode "FULL";

sleep 1;
waituntil {unitready _selectedunit};
_selectedunit lookat objnull;
_selectedunit dowatch objnull;
deletevehicle _marker;

This post was edited by warbird (2017-02-09 19:15, 307 days ago)


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 57
In-game name: Kobayashi Maru

 
#9 Posted at 2017-02-06 03:29        
     
Wow! Not sure you tested your code before..

init.sqf:
if (!isServer) exitWith {}; // no sense as in SP/hosted player is in server, in MP dedicated, there is no player on server.
if (!hasInterface) exitWith {}; // preferable, but be sure there will be no code for a dedi server (or HC) below this line.
sleep 1; // wath for?
waitUntil {!isNull (findDisplay 46)}; // preferable
(findDisplay 46) displaySetEventHandler ["KeyDown","_nil = _this execVM ""selectUnit.sqf"""]; // works also
titleText ["Press windows Left key once to activate script","plain down"];

selectUnit.sqf

if (!isServer) exitWith {}; // no sense
private _handled = false; // see below, added a line because this variable is worthy to avoid script repetition while maintaining the key down...
sleep 0.1; // what for?
switch (_this select 1) do // mono case? --> use if .. then..
{
// KEY windows Left 
case 219: 
{
markerIcon = "Sign_sphere100cm_EP1" createVehicle [0,0,0];
_handled = true; // missing line. Now your script returns true and script doesn't repeat if key stays down.
titleText ["Select any unit (F2,F3,F4..F12) once & point cursor towards position to move unit to position!","plain down"];

sleep 1;
hintsilent "select any single unit in 5 seconds!"; // a loop could be fine below.

sleep 1;
hintsilent "select unit in 5";
sleep 1;
hintsilent "select unit in 4";
sleep 1;
hintsilent "select unit in 3";
sleep 1;
hintsilent "select unit in 2";
sleep 1;
hintsilent "select unit in 1";
sleep 1;

SquadUnits = groupSelectedUnits player;
unit = Squadunits select 0; 

sleep 1; // what for?
if (vehicle unit!= unit) exitwith {hintsilent "Selected unit cannot move while in vehicle!,call script again!";deletevehicle markerIcon;};

sleep 1; // what for?
if (isNil "unit") exitwith {hintsilent "No unit selected,call script again!";deletevehicle markerIcon;};

hintsilent "unit selected!";

moveai = [markerIcon,unit] execVM "setunitpos.sqf"; 
waituntil {scriptdone moveai};

hintsilent "Select other units!";
};
};
_handled;

setUnitPos.sqf
_marker = _this select 0;
_selectedunit = _this select 1;
sleep 1; // what for?
_marker attachTO [player,[0,3,1.3]];
 
sleep 5;
_marker setvelocity [0,0,0]; // useless.
detach _marker;
_marker setPosATL getPosATL player; // useless because the line below
_marker setposATL (player modelToWorld [0,3,0]); // So 3 meters in front of player?? Where is the cursor? I was waiting for something like an "onEachFramed" screenToWorld [0.5,0.5] 

sleep 0.1;
_selectedunit lookat _marker; // what for?
_selectedunit dowatch _marker; // useless if the line above
_selectedunit domove getposATL _marker;
_selectedunit setspeedmode "FULL";

sleep 1;
waituntil {unitready _selectedunit};
_selectedunit lookat objnull;
_selectedunit dowatch objnull;
deletevehicle _marker;

exit; // useless

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 87
Rank:


Level: Member

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

 
#10 Posted at 2017-02-06 04:46        
     
This script is only for placing units at any height in buildings level like rooftops or any floor level etc not for placing on terrain level thats why I didnt use screentoworld because it will only place the visual marker on terrain/ground not on structures floor level.And there is no command for moving the visual marker with cursor.Thanks for correcting missing codes.

Anyway anyone can make their own AI scripts with these script i was only
using these to see if one can select units or not.You can use AI-related
commands here-
https://community.bistudio.com/wiki/Category:Scripting_Commands_ArmA2
https://community.bistudio.com/wiki/ArmA:_Actions

init.sqf
sleep 1;
disableSerialization;
_display = findDisplay 46;
_display displaySetEventHandler ["KeyDown","_nil = _this execVM ""selectUnit.sqf"""];
titleText ["Press windows Left key once to activate script","plain down"];

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

sleep 0.1;
switch (_this select 1) do
{
// KEY windows Left 
case 219: 
{
_handled = true;
hintsilent "select any single unit in 5 seconds!";

sleep 1;
hintsilent "select unit in 5";
sleep 1;
hintsilent "select unit in 4";
sleep 1;
hintsilent "select unit in 3";
sleep 1;
hintsilent "select unit in 2";
sleep 1;
hintsilent "select unit in 1";
sleep 1;

SquadUnits = groupSelectedUnits player;
unit = Squadunits select 0; 

sleep 1;//Exit script if selected AI is in vehicle.
if (vehicle unit!= unit) exitwith {hintsilent "Selected unit cannot move while in vehicle!,call script again!";};

sleep 1;//Exit script if no AI unit is selected.
if (isNil "unit") exitwith {hintsilent "No unit selected,call script again!";};

hintsilent "unit selected!";

//Your code or script handle here....

};
};
_handled;

This post was edited by warbird (2017-02-15 21:13, 301 days ago)


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 57
In-game name: Kobayashi Maru

 
#11 Posted at 2017-02-06 07:32        
     
Where are the building positions???
And, may I suggest you to trigger this while windows key is down, then freeze and go when windows key is up?
Why do you limit this script to one unit only?

This post was edited by Pierre MGI (2017-02-06 07:49, 311 days ago)

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 87
Rank:


Level: Member

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

 
#12 Posted at 2017-02-23 16:32        
     
I have edited my script now u can select single as well as multiple units with this version.
Place init.sqf, selectunits.sqf & setunitspos.sqf in your mission folder.
init.sqf
waitUntil {!isNull(findDisplay 46)}; 
disableSerialization;
_display = findDisplay 46;
_display displaySetEventHandler ["KeyDown","_nil = _this execVM ""selectUnits.sqf"""];

titleText ["Press windows Left key once to activate script","plain down"];

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

sleep 0.1;
switch (_this select 1) do
{
// KEY windows Left 
case 219: 
{
markerIcon = "Sign_arrow_down_large_EP1" createVehicle [0,0,0];
titleText ["Select any units (F2,F3,F4..F12) once & place marker towards position to move units to position!","plain down"];
_handled = true;

sleep 1;
hintsilent "select units in 5 seconds!";

sleep 1;
hintsilent "select units in 5";
sleep 1;
hintsilent "select units in 4";
sleep 1;
hintsilent "select units in 3";
sleep 1;
hintsilent "select units in 2";
sleep 1;
hintsilent "select units in 1";
sleep 1;

SquadUnits = groupSelectedUnits player;
countunits = count squadUnits;

sleep 0.1;
if (countunits == 0) exitwith {hintsilent "No units selected!,initiate script again!;";deletevehicle _marker;};

sleep 1;
hintsilent "units selected!";

moveai = [markerIcon,SquadUnits] execVM "setunitspos.sqf";
waituntil {scriptdone moveai};

hintsilent "Select other units!";
};
};
_handled;

setunitspos.sqf
_marker = _this select 0;
_selectedunits = _this select 1;

sleep 1;
_marker attachTO [player,[0,3,1.3]];
 
sleep 5;
_marker setvelocity [0,0,0];
detach _marker;
_marker setPosATL getPosATL player;
_marker setposATL (player modelToWorld [0,3,0]);

sleep 0.1;
{_x dowatch _marker} foreach _selectedunits;
{_x domove getposATL _marker} foreach _selectedunits;
{_x setspeedmode "FULL"} foreach _selectedunits;

sleep 1;
waituntil {{unitready _x} foreach _selectedunits;};
_selectedunits dowatch objnull;
deletevehicle _marker;

exit;