Jump to content
Sign in to follow this  
eagledude4

Type array expected...

Recommended Posts

I'm receiving an error on this line:

if (getpos ExecDealer != posExecDealer) then {

posExecDealer is defined as:

posExecDealer = getPos ExecDealer;

Share this post


Link to post
Share on other sites

You cannot compare positions, eg. [10, 20, 0] != [15, 15, 0] it not permitted. You can however check that their distance is very little:

if ( (getPos ExecDealer) distance posExecDealer < 5) then {

Which is true if they are less than 5m from each other.

Share this post


Link to post
Share on other sites

Thanks. Also, is it possible to do a foreach loop for this?:

posExecDealer = getPos ExecDealer;
posUsedDealer = getPos UsedDealer;

if ((getPos ExecDealer) distance posExecDealer > 1) then {
ExecDealer setpos posExecDealer;
};

if ((getPos UsedDealer) distance posUsedDealer > 1) then {
UsedDealer setpos posUsedDealer;
};

Edited by eagledude4

Share this post


Link to post
Share on other sites

Is the stuff in red right? ... somehow that doesn't seem to make much sense... but it might!

if ((getPos ExecDealer) distance posExecDealer > 1) then {
ExecDealer setpos posExecDealer;
};

if ((getPos UsedDealer) distance posUsedDealer > 1) then {
[color="#FF0000"]ExecDealer setpos posExecDealer;[/color]
};

Shouldn't it be:-

if ((getPos UsedDealer) distance posUsedDealer > 1) then {
[b]UsedDealer[/b] setpos [b]posUsedDealer[/b];
};

Share this post


Link to post
Share on other sites

Yes, sorry. What the script is supposed to do is define the location of each npc by doing:

posUsedDealer = getPos UsedDealer;

and then later loop if their location has changed. If it has changed, to put them back in the original position. I use the npcs as shops in my RP Mod and this prevents people from moving the npcs around :) What I meant by my loop question was: Is there a way to make a loop function instead of having

if ((getPos UsedDealer) distance posUsedDealer > 1) then {
ExecDealer setpos posExecDealer;
};

for every single npc I have.

Edited by eagledude4

Share this post


Link to post
Share on other sites

Kylania is right, I, used the '<' when I should have used '>'. If your goals is to just not have the ai's move there might be a better solution. Put this in their init line:

this disableAI "MOVE";

Then they should no longer move around, and you won't need a script to continously reposition them.

Share this post


Link to post
Share on other sites

I already have that in the init for all my AI.

The above prevents ai from moving themselves, not other players forcing them to move. And when did kylania reply? :P

Edited by eagledude4

Share this post


Link to post
Share on other sites
... And when did kylania reply? :P

Ooops. Brainfart. Sry twirly... Was probably having multiple tabs open and switching at the time.

Share this post


Link to post
Share on other sites
Is there a way to make a loop function instead of having

Code:

if ((getPos UsedDealer) distance posUsedDealer > 1) then {
ExecDealer setpos posExecDealer;
};

for every single npc I have.

It's a bit tricky since you use 2 variables, the original position, and the unit, for each npc.

If you do put this in your init for your npc's then it becomes easier since we only have to know the npc. (although subjectively not simpler).

this setVariable ["HoldPos", getPos this];

Then you can have a single script:

if (!isServer) exitWith {};

_npcs = [usedDealer, ExecDealer, ......., LastDealer];

while {true} do {
  {
       _holdPos = _x getVariable "HoldPos";
       //Check that the position have not been "ruined" - unlikely to happen, but better than teleporting your npcs out to nothing:
       if (!isNil _holdPos) then {
           if ((getPos _x) distance _holdPos > 1) then {
               _x setPos _holdPos;
           };
       };
  } forEach _npcs;
  sleep 2 + random 5;
};

Share this post


Link to post
Share on other sites

Instead of

this setVariable ["HoldPos", getPos this];

use

this setVariable ["HoldPos", getPos this, true];

Makes setVariable value global

Share this post


Link to post
Share on other sites

Why would you need to make it global if only the server is doing it ? :)

Share this post


Link to post
Share on other sites

That was exactly what I was looking for, however, I got the type array expected string,code error for the !isNil condition, so I took it out of the code. and now the positions aren't getting reset.

Edited by eagledude4

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  

×