Jump to content
vonlugar

Help on Waypaths Script

Recommended Posts

I'm new to major coding sequences. I've been able to get simple 1-step, 2-step tasks done with what I can understand from online. I really struggle with unknown unit commands (_x, _this, _thislist, foreach)

After about of week of research, and tests in map editor, I'm not finding a solution to my goal.


What I'm trying to accomplish:
A Unit(opfor) is moved to a area/location. A trigger is activated when it detects them at that location, finds the nearest player, runs up to them and explodes. (i have an attached trigger to the opfor unit so when a player is inside the range, it creates and bomb at the location).

This is planned for a multiplayer game, LAN based, so it doesn't have to be for dedicated servers.

 

Now. I've tried 2 ways of getting the Opfor unit to that location, and it still fails at not moving. I'm assuming I'm not finding a location to send them too.

 

1st.

An already created Opfor unit is on the map;
I move them to a random position in the trigger location.
Upon landing i have:

 

Condition:

thislist = [slime_gr_1, slime_gr_2, slime_gr_3, slime_gr_4, slime_gr_5, slime_gr_6, slime_gr_7, slime_gr_8, slime_gr_9, slime_gr_10, slime_gr_11, slime_gr_12, slime_gr_13, slime_gr_14, slime_gr_15, slime_gr_16, slime_gr_17, slime_gr_18, slime_gr_19, slime_gr_20, slime_gr_21];

names of all the units i have already made, so the trigger only reacts to these names being "present" in the location.

Activation:

[] spawn{
_markerPos = getMarkerPos "mrk_ooze";
_playerList = allPlayers apply {[_markerPos distanceSqr _x, _x]};
_playerList sort true;
_closestPlayer = (_playerList select 0) param [1, objNull];
_mrk = _closestPlayer;  
_x doMove _mrk;
};

The unit doesn't move, they just stand there.
Its the _x calling I can't seem to understand, and reading up on the Arma website doesn't help explain it.
 

 

2nd.

I've tried creating the unit at the location without the trigger upon landing. Which lead to other problems that I haven't looked at yet. (attaching a smoke grenade and trigger for bomb
 

[] spawn{
_areaR = [[5050.288, 2841.632, 0], [5069.165, 2841.630, 0], [5088.359, 2841.634, 0]];
_spawn1 = selectRandom _areaR;
_grp_gr = createGroup opfor;
_ooze_gr = _grp_gr createUnit ["O_Soldier_VR_F", _spawn1, [], 0, "CAN_COLLIDE"];
_ooze_gr setUnitPos "MIDDLE";
_smoke = createvehicle ["SmokeShellGreen",_spawnR,[],0,"none"];
_smoke attachTo [_ooze_gr, [0,0,0.5]];
sleep 45;
};

Without trying to use _x. But then I couldn't find a way to get the unit to find a nearest player, move or create a waypoint there, and move them.
I'm stuck at finding the nearest player. I've looked up "nearestObject" and "nearEntities" but it seems like those don't look for player but a specific model; ("man", "sheep", "car")
 

So I moved to just finding the distance of a player to the unit, if that value is less than a set variable, "_x doMove player". And still I can't get any opfor that falls into a trigger to move, only when I call it's variable name to do the command.

I'm sure i'm doing something over-complicated or wrong, but I can't wrap my head around it.
Can anyone help or guide me?

 

 

 

 

 

 


 

Share this post


Link to post
Share on other sites

_x is a special or "magic" variable which exist inside of some loops only. There it represents the current element that is treated.

The command apply creates such a loop therefore _x exists inside of its curly brackets.

 

you are trying to use _x outside of such a loop but there its just not existing. instead of _x in the line

_x doMove _mrk;

you have to use the object or variablename of your opfor unit.

 

Also your condition field seems completely wrong to me.

thisList is an array where all objects are stored (by trigger) which have activated the trigger currently.

You can't just store your squad unit members there. You have to look if your squad members are stored in thisList. If thats the case than you know which squad member/s did activate the trigger. Maybe you don't need that.

You should read this to understand triggers, its fields and variables better:

https://community.bistudio.com/wiki/Eden_Editor:_Trigger

 

the condition field is as it says a condition which must be true to activate a trigger. if u are able to activate the trigger by avtivation field and if that is enough for your purpose then the condition field contains just this. this is here the result of your activation condition. if it is true then your trigger is activated.

Share this post


Link to post
Share on other sites
2 hours ago, vonlugar said:

I'm new to major coding sequences. I've been able to get simple 1-step, 2-step tasks done with what I can understand from online. I really struggle with unknown unit commands (_x, _this, _thislist, foreach)

After about of week of research, and tests in map editor, I'm not finding a solution to my goal.


What I'm trying to accomplish:
A Unit(opfor) is moved to a area/location. A trigger is activated when it detects them at that location, finds the nearest player, runs up to them and explodes. (i have an attached trigger to the opfor unit so when a player is inside the range, it creates and bomb at the location).

This is planned for a multiplayer game, LAN based, so it doesn't have to be for dedicated servers.

 

Now. I've tried 2 ways of getting the Opfor unit to that location, and it still fails at not moving. I'm assuming I'm not finding a location to send them too.

 

1st.

An already created Opfor unit is on the map;
I move them to a random position in the trigger location.
Upon landing i have:

 

Condition:


thislist = [slime_gr_1, slime_gr_2, slime_gr_3, slime_gr_4, slime_gr_5, slime_gr_6, slime_gr_7, slime_gr_8, slime_gr_9, slime_gr_10, slime_gr_11, slime_gr_12, slime_gr_13, slime_gr_14, slime_gr_15, slime_gr_16, slime_gr_17, slime_gr_18, slime_gr_19, slime_gr_20, slime_gr_21];

names of all the units i have already made, so the trigger only reacts to these names being "present" in the location.

Activation:


[] spawn{
_markerPos = getMarkerPos "mrk_ooze";
_playerList = allPlayers apply {[_markerPos distanceSqr _x, _x]};
_playerList sort true;
_closestPlayer = (_playerList select 0) param [1, objNull];
_mrk = _closestPlayer;  
_x doMove _mrk;
};

The unit doesn't move, they just stand there.
Its the _x calling I can't seem to understand, and reading up on the Arma website doesn't help explain it.
 

 

2nd.

I've tried creating the unit at the location without the trigger upon landing. Which lead to other problems that I haven't looked at yet. (attaching a smoke grenade and trigger for bomb
 


[] spawn{
_areaR = [[5050.288, 2841.632, 0], [5069.165, 2841.630, 0], [5088.359, 2841.634, 0]];
_spawn1 = selectRandom _areaR;
_grp_gr = createGroup opfor;
_ooze_gr = _grp_gr createUnit ["O_Soldier_VR_F", _spawn1, [], 0, "CAN_COLLIDE"];
_ooze_gr setUnitPos "MIDDLE";
_smoke = createvehicle ["SmokeShellGreen",_spawnR,[],0,"none"];
_smoke attachTo [_ooze_gr, [0,0,0.5]];
sleep 45;
};

Without trying to use _x. But then I couldn't find a way to get the unit to find a nearest player, move or create a waypoint there, and move them.
I'm stuck at finding the nearest player. I've looked up "nearestObject" and "nearEntities" but it seems like those don't look for player but a specific model; ("man", "sheep", "car")
 

So I moved to just finding the distance of a player to the unit, if that value is less than a set variable, "_x doMove player". And still I can't get any opfor that falls into a trigger to move, only when I call it's variable name to do the command.

I'm sure i'm doing something over-complicated or wrong, but I can't wrap my head around it.
Can anyone help or guide me?
 

 

ouch!

You need to read some basics!

First of all : sign  =  is for assigning the result of expression on the right to the variable on the left, not for comparing two similar data (use == ).

 

if you want a condition for checking if a unit is in area of a trigger, you can use preset condition like BLUFOR present, then something added in condition field of the trigger id needed. On sure thing thisList refers to the preset condition. If you let the trigger to none , none, thisList will return [].
If preset condition seems to be not adapted for your aim, you can let the trigger none, none but forget thisList.

 

for players (MP) :
 the trigger can fires with:
allPlayers isNotEqualTo [] && allPlayers findIf {_x inArea thisTrigger} > -1

for an array of units:

[slime_gr_1, slime_gr_2, slime_gr_3, slime_gr_4, slime_gr_5, slime_gr_6, slime_gr_7, slime_gr_8, slime_gr_9, slime_gr_10, slime_gr_11, slime_gr_12, slime_gr_13, slime_gr_14, slime_gr_15, slime_gr_16, slime_gr_17, slime_gr_18, slime_gr_19, slime_gr_20, slime_gr_21] findIf {_x inArea thisTrigger} > -1

Next step, you can find who entered the trigger by:
in on activation field:
 

0 = thisTrigger spawn {
  private _Candidates = [slime_gr_1, slime_gr_2, slime_gr_3, slime_gr_4, slime_gr_5, slime_gr_6, slime_gr_7, slime_gr_8, slime_gr_9, slime_gr_10, slime_gr_11, slime_gr_12, slime_gr_13, slime_gr_14, slime_gr_15, slime_gr_16, slime_gr_17, slime_gr_18, slime_gr_19, slime_gr_20, slime_gr_21] select {_x inArea _this};
  private _targetedPlayer = selectRandom _candidates;
  
  
};

You can expand with your code for the bomber.
 

Share this post


Link to post
Share on other sites
On 6/3/2021 at 1:06 AM, pierremgi said:

if you want a condition for checking if a unit is in area of a trigger, you can use preset condition like BLUFOR present, then something added in condition field of the trigger id needed. On sure thing thisList refers to the preset condition. If you let the trigger to none , none, thisList will return [].
If preset condition seems to be not adapted for your aim, you can let the trigger none, none but forget thisList.

 

So I was setting the condition to:
Opfor.
present.

in condition field: the list of units that i want to use as the bomber.
i did this because I had other opfor around the area and I didn't want them to trigger it during fighting.

 

I'm interested in the last bit pierremgi coded up. I could try selecting a random bomber during the same field as sending them to a waypoint. Rather than trying to find who stepped into the trigger, which is where i think nothing was happening.
 

 

can you just call a variable you describe without having it be an Arma code?

[] spawn{
private _targetedPlayer = selectRandom _candidates;
_targetedPlayer;
};


***UPDATE***
So i moved the array to the same field as finding the player. And it does work. No landing trigger zone for the opfor anymore.
I had to setup an array of allPlayers in the trigger area, selectRandom from that array, then doMove to that.

[] spawn{
_green = [slime_gr_1, slime_gr_2, slime_gr_3, slime_gr_4, slime_gr_5, slime_gr_6, slime_gr_7, slime_gr_8, slime_gr_9, slime_gr_10, slime_gr_11, slime_gr_12, slime_gr_13, slime_gr_14, slime_gr_15, slime_gr_16, slime_gr_17, slime_gr_18, slime_gr_19, slime_gr_20, slime_gr_21];
_areaR = [[5050.288, 2841.632, 0], [5069.165, 2841.630, 0], [5088.359, 2841.634, 0]];
_spawn1 = selectRandom _areaR;
_add1 = selectRandom _green;
_getarea = allPlayers inAreaArray boss_fighting_zone;
_getplayer = selectRandom _getarea;
_find1 = getPOS _getplayer;
_add1 setPOS _spawn1;
_add1 doMove _find1;
};

But my next silly problem is the selectRandom of the opfor bomber, will still pull a dead unit.
I figured i could do an if statement to check the selectRandom and if !alive repeat, which i only understand if-else loops from python, where you would call the statement again if it failed. Doesn't seem to work in arma the way i thought.

is there a better way to check alive or !alive from an array?

 

 

 

Edited by vonlugar
updating info

Share this post


Link to post
Share on other sites
//pick a random living unit
_add1 = selectRandom ( _green select {alive _x} );

 

  • Thanks 1

Share this post


Link to post
Share on other sites
19 hours ago, sarogahtyp said:

//pick a random living unit _add1 = selectRandom ( _green select {alive _x} );

 

so calling _x in here is like a loop? or is it inherit to the group/code being used in the same line?

 

It works, just trying to understand _X some more

Share this post


Link to post
Share on other sites
23 hours ago, sarogahtyp said:

//pick a random living unit
_add1 = selectRandom ( _green select {alive _x} );

 

 

select can be used as a kind of loop if you use it with curly brackets. the loop executes the code inside the brackets for each element of the given array (_green)

inside those brackets there has to be a condition.

the _x represents the current element of the loop.

if that condition is true then select puts the current element into the returning array.

if it is false then the current element  just gets skipped.

therefore  inside the round brackets the select command creates an array with all alive objects of the array green

that resulting array feeds selectRandom which picks a random element of it.

 

read the bibki of each command you use in your code. there it is explained.

  • Like 2
  • Thanks 1

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

×