Jump to content

Recommended Posts

Hi everybody !

I come here to search some help ! Indeed I want to make a script with a big array who coutains all coordonate of home and the name of the owner. I know how do the array BUT I don't know how to make a script which gives the name of the owner of the house where my character is in arma 3. Basically I would like to search in my array let's call the _Home the owner of the house where is my character.

If somebody can help me a little it could be nice !

 

Thanh kyou

!!

 

  • Haha 1

Share this post


Link to post
Share on other sites

What is the structure of the array, what elements do you want to pull from it, and how do you want to use them. Show an example of the array here, please.

  • Like 1

Share this post


Link to post
Share on other sites
_Array = [[Player1, coordonates1],[Player2, coordonates2]];



and I want to check with getpos player if the coordinates exist in the array and bring out the name of the owner.

 

Thx @Harzach

Share this post


Link to post
Share on other sites
_owner = objNull;
{if (player distance (_x select 1) < 5) then {_owner = _x select 0};} forEach _Array;

5 is just suggestive radius for "inside a house".  Houses will be bigger or smaller. Or use 1 or 0 if you want player right on the spot.

  • Like 3

Share this post


Link to post
Share on other sites

Opusfmspol's solution most probably works well, but since you mentioned that this array is large, you may want to resort to findIf, which will provide somewhat better performance (it will stop searching when the condition you set returns true).

 

Opusfmspol's code should then become something like

// _array: The array to look through
// _owner: The owner of the house the player is in
// _idx: The index of the element for which the condition returned true

_owner = objNull; // Initialise owner
_idx = _array findIf {player distance (_x select 1) < 5}; // Search through the array

// Make sure to check that the condition returned true at some point
if (_idx != -1) then {
    _owner = (_array select_idx) select 0; // Set the owner
};

Now, this may seem a bit of "overburden" because you have to check for the returned value, but it in most cases (if the house is not towards the end of the array) it will provide some performance increase.

 

Please, note that this code is NOT tested, so please treat it accordingly.

  • Like 3

Share this post


Link to post
Share on other sites

Hi @ZaellixA !

I have another problem with this big Array...

I want to recup another array and check if a value is == 1 I put a litte code for example.

 

_infos = missionNameSpace getVariable ["array", 0]; // I recup my array

_test = _infos select 4; // I want that _test recup the value of the 4 value (the fourth value is equal to 1)

if ( _test == 1) then {
hint "blablabla";
};

but when I do that I have an error about the type of value.

 

Can You help me please or somebody else pelase 🙂

 

Thx

Share this post


Link to post
Share on other sites
17 hours ago, Minal said:

Hi @ZaellixA !

I have another problem with this big Array...

I want to recup another array and check if a value is == 1 I put a litte code for example.

 


_infos = missionNameSpace getVariable ["array", 0]; // I recup my array

_test = _infos select 4; // I want that _test recup the value of the 4 value (the fourth value is equal to 1)

if ( _test == 1) then {
hint "blablabla";
};

but when I do that I have an error about the type of value.

 

Can You help me please or somebody else pelase 🙂

 

Thx

Hhhmm... Not sure about it. Would you care to be a bit more specific on what the structure of the "array" variable is?

 

From what I understood though, the fifth element of the "array" should be 1 and you want to get that?

 

It may also be helpful to send either a mission with it or a simple script that replicates the error (I believe the second is better, as I believe that full missions are a bit of an overkill).

  • Like 1

Share this post


Link to post
Share on other sites

thx for your reply  @ZaellixA but i have find the solution thx

  • Like 1

Share this post


Link to post
Share on other sites

Would you care to share it, because someone may benefit from it in the future?

  • Like 2

Share this post


Link to post
Share on other sites

The problem was that in my test I didn't have to put a 0 at the end but []

_infos = missionNameSpace getVariable ["array", 0]; //broken

_infos = missionNameSpace getVariable ["array", []]; // The solution

  • Like 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

×