Jump to content
Sign in to follow this  
[frl]myke

[Beginners guide]: Arrays

Recommended Posts

To concatinate strings with variables, you should opt to use format.

_debug = format["http://dev.taskforce47.de/missingAddons.php?map=%1&mission=%2&player=%3&missing=%4,%5", _map, _mission, _player, (_missing select 0), (_missing select 1)];  

Share this post


Link to post
Share on other sites

Hi Guys!

I wrote this script to spawn enemies:

if (lisServer) exitWith {};

_spawnPos = markerPos (_this select 0);

_group1 = createGroup EAST;

_unit1 = _group1 createUnit ["TK_Soldier_SL_EP1", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; sleep 0.2;

_unit2 = _group1 createUnit ["TK_Soldier_AT_EP1", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; sleep 0.2;

_unit3 = _group1 createUnit ["TK_Soldier_B_EP1", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; sleep 0.2;

_unit4 = _group1 createUnit ["TK_Soldier_GL_EP1", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; sleep 0.2;

_unit5 = _group1 createUnit ["TK_Soldier_MG_EP1", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; sleep 0.2;

_unit6 = _group1 createUnit ["TK_Soldier_Medic_EP1", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; sleep 0.2;

_unit7 = _group1 createUnit ["TK_Soldier_EP1", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; sleep 0.2;

_waypoint = _group1 addWaypoint [getmarkerpos "wp0",0];

[group1, 1] setWaypointType "MOVE";

[group1, 1] setWaypointFormation "STAG COLUMN";

[group1, 1] setWaypointBehaviour "SAFE";

_waypoint2 = _group1 addWaypoint [getmarkerpos "wp1",50];

[group1, 1] setWaypointType "SAD";

[group1, 1] setWaypointFormation "STAG COLUMN";

[group1, 1] setWaypointBehaviour "SAFE";

Everything working fine, but the group does not take the formation/behaviour/etc. as set..So the "set"-s do not work..

Could anybody help, please..?!

Share this post


Link to post
Share on other sites

_waypoint = _group1 addWaypoint [getmarkerpos "wp0",0];
[group1, 1] setWaypointType "MOVE";
[group1, 1] setWaypointFormation "STAG COLUMN";
[group1, 1] setWaypointBehaviour "SAFE";

_waypoint2 = _group1 addWaypoint [getmarkerpos "wp1",50];
[group1, 1] setWaypointType "SAD";
[group1, 1] setWaypointFormation "STAG COLUMN";
[group1, 1] setWaypointBehaviour "SAFE";

Everything working fine, but the group does not take the formation/behaviour/etc. as set..So the "set"-s do not work..

Could anybody help, please..?!

"setWaypoint ...." for waypoint settings is not the same sort of command as "Set" which is used for arrays.

"Set" and "SetWaypoint..." are separate commands with different functions.

"Set" is a command that affects an ARRAY.

Notice in the wiki's "Syntax" portion that ARRAY is listed before the command:

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

"setWaypoint ..." are commands that affect a WAYPOINT.

Notice in the wiki's "Syntax" portion that WAYPOINT is listed before the commands:

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

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

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

Your commands don't work because you're running waypoint commands on arrays. You need to run them on the waypoints instead.

_waypoint = _group1 addWaypoint [getmarkerpos "wp0",0];
_waypoint setWaypointType "MOVE";
_waypoint setWaypointFormation "STAG COLUMN";
_waypoint setWaypointBehaviour "SAFE";

_waypoint2 = _group1 addWaypoint [getmarkerpos "wp1",50];
_waypoint2 setWaypointType "SAD";
_waypoint2 setWaypointFormation "STAG COLUMN";
_waypoint2 setWaypointBehaviour "SAFE";

While the waypoint itself returns an array, the array method won't work unless it's exactly what the return should be from the referenced waypoint. Thus the waypoint variable itself is what should be used. It helps ensure the array that 'setWaypoint...' uses has the correct content.

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

Hi!

I tried it and does not work..

I set the waypointSpeed "FULL" but they still walk..not run..(they run only if nothing set to the waypoint)

What should i do..?!

---------- Post added at 08:46 ---------- Previous post was at 08:35 ----------

OK..Now i have solved the problem..

Thank's!

Cheers

Share this post


Link to post
Share on other sites

- I have unit consisting of soldiers A1 A2 A3 A4.........................A12

- Then I have a hostage named Hostage1.

-then i have a trigger

-I want to fire the trigger when either of the A1 - A12 guys approaches the hostage.

For one guy i can do:

 A1 distance Hostage1 < 5

or

 A2 distance Hostage1 < 5

that works.

Then i tried:

A1||A2||A3||A4||A5||A6||A7||A8||A9||A10||A11||A12 distance Hostage1 < 5

that didnt work.

then i tried:

A1 distance Hostage1 < 5 || A2 distance Hostage1 < 5 || A3 distance Hostage1 < 5 

no joy either.

then i tried:

{x distance Hostage1 < 5;} forEach units group player

resulted in error

so i want to try array but from the first post i learn nothing if anything, it only confuses me more. so how would i do what i need using arrays?

Share this post


Link to post
Share on other sites

{ _x distance Hostage1 < 5 } count units group player > 0

The inner part checks distance, the outer part checks if more than 0 group members qualify.

Share this post


Link to post
Share on other sites

Disregard, found my own suggestion didn't work either, trying to find out why

{ _x distance Hostage1 < 5 } count units group player > 0

The inner part checks distance, the outer part checks if more than 0 group members qualify.

I thought Count command returned a number rather than an object - or will it return the represented object from the array as well? The distance command needs to determine distance between two objects. Does the _x return the object and the count return the number?

--- Edit --

Disregard, tested and YES! Very nice to know, I can use that in my mission too, to find out if any group members are by a UAV terminal. Thanks AZCoder!

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

Thank you guys :-) it works like charm, and for this mission it is sufficient.

But still. how would i do it when i would like to have only certain members of the player team be able to trigger it? Like the guys A1 A2 A3 A4 and so? i gues i would have to employ array somewhat.

Share this post


Link to post
Share on other sites
how would i do it when i would like to have only certain members of the player team be able to trigger it? Like the guys A1 A2 A3 A4 and so?

In this instance units group player returns an array of the entire player group, so it would be a matter of replacing it with an array of your own choice.

You could simply assign it:

_array = [A1,A2,A3,A4];
{_x distance Hostage1 < 5} count _array > 0;

... or declare the empty array first and build it depending on what you filter to add into it:

_array = [];
if ([i][color="#FF0000"]<return from unit is true>[/color][/i]) then {_array = _array + [[i][color="#FF0000"]<unit>[/color][/i]];};
{_x distance Hostage1 < 5} count _array > 0;

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

Thank you, the first thing i understand, the scond:

... or declare the empty array first and build it depending on what you filter to add into it:

_array = [];
if ([i][color="#FF0000"]<return from unit is true>[/color][/i]) then {_array = _array + [[i][color="#FF0000"]<unit>[/color][/i]];};
{_x distance Hostage1 < 5} count _array > 0;

I dont. What that does?

I have another idea, what if i have several soldiers, and several hostages?

And i want the trigger to fire when any of the soldiers gets close to any of the hostages?

Soldiers in group: A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12

Hostges: Hostage1, hostage2, hostage3,

Would that work?:

trigger condition:

 
        rescue=[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12];
       Hostage=[Hostage1, hostage2, hostage3];
       {x  distance Hostage < 5} count rescue > 0;

Share this post


Link to post
Share on other sites

Mirek, what exactly are you trying to do here?

Looks to me that it would be best to use addAction on the hostages, then you can use the condition of the addAction with _this and _target to have the action available or not.

Maybe wrong direction, but if you want to free the hostages? kylania has one example: Hostage Capture Script (addAction) which you could easily modify the condition

Edited by panther42

Share this post


Link to post
Share on other sites
Thank you, the first thing i understand, the scond: I dont. What that does?

It uses an if-then to add only the desired elements into the array. If-then is a true/false test ("boolean"), so whatever the (condition) is, it must return a boolean value: either TRUE or FALSE.

An example scenario:

You have a group of mixed players and AI:

A1: player

A2: AI

A3: AI

A4: player

A5: AI

A6: player

You only want the check to occur for players, so you build an array containing the group's players.

The "isPlayer" command will return a boolean true/false value.

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

[i][color="#808080"]// The group A1 belongs to is designated _rescue.[/color][/i]
_rescue = group A1;

[i][color="#808080"]// The empty array is declared.[/color][/i]
_rescuePlayers = [];

[i][color="#808080"]// A "forEach" check of group _rescue adds player units into the array, filtering out the AI.[/color][/i]
{
if ([color="#FF0000"]isPlayer _x[/color]) then {_rescuePlayers = _rescuePlayers + [[color="#FF0000"]_x[/color]]};
} forEach [color="#FF0000"]units _rescue[/color];

[i][color="#808080"]// "isPlayer" returns true or false.  If true, the unit being tested is added into the array.
// The resulting array: _rescuePlayers = [A1,A4,A6][/color][/i]

[i][color="#808080"]// Distance check is made from the array of players.[/color][/i]
{_x distance Hostage1 < 5} count _rescuePlayers > 0;

tested, and this works in a trigger:

rescue = group A1;
rescuePlayers = [];
{if (isPlayer _x) then {rescuePlayers = rescuePlayers + [_x]};} forEach units rescue;
{_x distance Hostage1 < 5} count rescuePlayers > 0;

Would that work?:

         rescue=[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12]; 
       Hostage=[Hostage1, hostage2, hostage3]; 
       {x  distance Hostage < 5} count rescue > 0;

No, because "Hostage" is an array of objects, and not an object. "Distance" checks the distance between two objects, locations or positions. The code would have to be reworked to cycle through the objects in the rescue and Hostage arrays, which can be done but you're looking at cycling two arrays to obtain a true return for the trigger. Might look at panther42's suggestion for an easier approach with that.

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

Panther: But adActions i allready know, arrays are new to me, so i want to use arrays. I could actually just place trigger with ?Bluefor detected by civilians, sinchronized with a waypoint and it would do the same,without any coding, but i dont want to do it that way, i want to try it with arrays.

Opus From South Pole: That looks nice, Thank you.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×