Jump to content
sizraide

Assigning a group within a variable.

Recommended Posts

Hello, i'm creating a COOP mission and I have a script here that enables the helicopter "move" and turn its engine on when the player enters it.


How can I make it so when the entire "group" of players enter the heli the heli turns its engine on and starts moving.

 

Quote

heli1 addEventHandler ["GetIn", {

    private _unit = player;

    private _heli1 = heli1;

 

    if (_unit in _heli1) then

    {

        _heli1 engineOn true;

        _heli1 enableAI "Move";

    };

}];

 

heli1 addEventHandler ["GetOut", {

    hint "Meet up with Sergeant Riley.";

}];

 

Share this post


Link to post
Share on other sites
heli1 addEventHandler ["GetIn", 
{
	//get group members of embarked unit
	private _units = units (_this select 2);

	//get number of group members
	private _units_num = count _units;

	//get number of group members in heli
	_in_heli_num = { _x in heli1 } count _units;

	if (in_heli_num isEqualTo _units_num) then
	{
		_heli1 engineOn true;
		_heli1 enableAI "Move";
	};
}];

heli1 addEventHandler ["GetOut", {

    hint "Meet up with Sergeant Riley.";
}];

 

Share this post


Link to post
Share on other sites

Made a little mistake. Will correct it in a few minutes.

Edit: but should work in singleplayer

Edit2: correction done

Share this post


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

heli1 addEventHandler ["GetIn", 
{
	//get group members of embarked unit
	private _units = units (_this select 2);

	//get number of group members
	private _units_num = count _units;

	//get number of group members in heli
	_in_heli_num = { _x in heli1 } count _units;

	if (in_heli_num isEqualTo _units_num) then
	{
		_heli1 engineOn true;
		_heli1 enableAI "Move";
	};
}];

heli1 addEventHandler ["GetOut", {

    hint "Meet up with Sergeant Riley.";
}];

 


Thanks for the solution!

Just asking I currently have "playergroup = group this;" in each players init, wondering if this affects the script?
 

Share this post


Link to post
Share on other sites
5 minutes ago, sizraide said:

Just asking I currently have "playergroup = group this;" in each players init, wondering if this affects the script?

 

what you do with this is that the group of the last player who is inited will be stored in playergroup.

 

I guess what you really want is to assign all players to the same group, right?

Share this post


Link to post
Share on other sites
1 minute ago, sarogahtyp said:

 

what you do with this is that the group of the last player who is inited will be stored in playergroup.

 

I guess what you really want is to assign all players to the same group, right?


Well nevermind what I said, but I tried your solution and it didn't work

but after some researching I came up with this and it works.

 

Quote

heli1 addEventHandler ["GetIn", {

 

    private _units = count playableUnits;

    private _pl = count allPlayers;

    private _heli1 = heli1;

 

    if ((_units) == (_pl)) then {

 

        _heli1 engineOn true;

        _heli1 enableAI "Move";

 

    };

}];

 

heli1 addEventHandler ["GetOut", {

    hint "Meet up with Sergeant Riley.";

}];


I couldn't get the count for players inside heli1 to work.

ended up comparing if all playable units are = all players.

  • Confused 1

Share this post


Link to post
Share on other sites

maybe you would need some braces there:

 

_in_heli_num = { (_x in heli1) } count _units;

 

you should just post error messages if a code does not work ... " couldn't get ... to work." is not enough in a scripting forum.

 

Also the code you posted in your last post should be complete nonsense. At least if your purpose is what you told - to check if all embarking group members are inside the heli already.

Share this post


Link to post
Share on other sites
5 minutes ago, sarogahtyp said:

maybe you would need some braces there:

 


_in_heli_num = { (_x in heli1) } count _units;

 

you should just post error messages if a code does not work ... " couldn't get ... to work." is not enough in a scripting forum.

 

Also the code you posted in your last code should be complete nonsense. At least if your purpose is what you told - to check if all embarking group members are inside the heli already.


Sorry, basically it didn't show any error messages.

The heli wouldn't turn on its engine.

 

I'll try your method again.

Share this post


Link to post
Share on other sites
17 minutes ago, sarogahtyp said:

maybe you would need some braces there:

 


_in_heli_num = { (_x in heli1) } count _units;

 

you should just post error messages if a code does not work ... " couldn't get ... to work." is not enough in a scripting forum.

 

Also the code you posted in your last post should be complete nonsense. At least if your purpose is what you told - to check if all embarking group members are inside the heli already.



Doesn't work. No error messages popping up, just heli won't turn on its engine and move.

Share this post


Link to post
Share on other sites

This _x is confusing me alot, how exactly do you use it?

Share this post


Link to post
Share on other sites
1 minute ago, sizraide said:

My COOP missions doesn't allow players to have AI in their group so I thought it'll be just better to compare playable units to all players.

 

how you know that playable units are inside of the heli?

 

Or are we are talking about players spawning inside the heli - not embarking?

Share this post


Link to post
Share on other sites
11 minutes ago, sizraide said:

This _x is confusing me alot, how exactly do you use it?

 

_x is a magic variable and represents the current element in some loops.

 

the count command as I used it counts all elements of the given array for which the condition inside the curly brackets is true.

so it should count every object of the array _units which is inside the heli.

 

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

Share this post


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

 

_x is a magic variable and represents the current element in a loop.

 

the count command as I used it counts all elements of the given array for which the condition inside the curly brackets is true.

so it should count every object of the array _units which is inside the heli.


I got it to work!

 

Quote

heli1 addEventHandler ["GetIn", 

{

    private _units = units (_this select 2);

    private _units_num = count _units;

    _in_heli_num = { _x in heli1 } count _units;

 

    if (_in_heli_num isEqualTo _units_num) then

    {

        heli1 engineOn true;

        heli1 enableAI "Move";

        hint "Script successful";

    };

}];

 

Removed the "_" behind heli1 and it worked somehow.

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

×