Jump to content
Sign in to follow this  
robot

Really simple question on getPos & setPos

Recommended Posts

Hi,

I am trying to teach myself scripting and something which is probably simple is proving unachievable (believe it not I just burned up a few hours doing this).

All I want to do is getPos of a unit and then setPos of the player so they are with the unit, or even setPos the unit (I can't get either to work).

Within the mission I have a Private Rifleman with control set to 'Player'. In the init line I have my script called...

script = [] execVM "myscript.sqf"

I also have a unit

Non Playable Damsel (Blue) (Classname Damsel1)

My failures:

_theunit = getPos unit;
x  = _theunit select 0;
y  = _theunit select 1;
z  = _theunit select 2;
player setPos [%1,%2,%3];

player setPos [((getPos unit select 0)+5),((getPos unit select 1)+5),0];

player setPos [((getPos Damsel1 select 0)+5),((getPos Damsel1 select 1)+5),0];

player setPos getPos unit;

player setPos getPos Damsel1;

_damsel = getPos unit;
x  = _damsel select 0;
y  = _damsel select 1;
z  = _damsel select 2;
player setPos [x,y,(z) +0.8];

There are also about 15 other combinations which all failed too! :( None of it is working and i am out of ideas.

I have scraped to the bottom Google and here search wise.

Share this post


Link to post
Share on other sites

Don't worry, robot. We all started to learn one day. And this is changing so fast that even the good guys like Kylania learn something every day.

Don't be shy about asking for help. Search Google for Mr Murray's editing guide. It's for an older version of the game, but 100% of it works in Arma 2 Arrowhead. Also, the Bohemia Biki is a useful resource, if not terribly helpful.

Share this post


Link to post
Share on other sites
player setPos (getPos Damsel1);

Hmm, my player did not move. I have put some hints in so I know the script is executing ok.

Here is the unit info:

h81Ve.png

Player:

uH3nr.png

---------- Post added at 16:28 ---------- Previous post was at 16:24 ----------

Don't worry, robot. We all started to learn one day. And this is changing so fast that even the good guys like Kylania learn something every day.

Don't be shy about asking for help. Search Google for Mr Murray's editing guide. It's for an older version of the game, but 100% of it works in Arma 2 Arrowhead. Also, the Bohemia Biki is a useful resource, if not terribly helpful.

Thanks for the kind words :)

Share this post


Link to post
Share on other sites

The damsel must be named "Damsel1" (without the ") in order to make the setpos work (according to your screenshot the damsel has no name, her name-field is emtpy).

Share this post


Link to post
Share on other sites

Notice you're not actually naming the Damsel in there. You'd want to have "Damsel1" in the Name field of her Edit Unit screen. This might look a little complicated but it'll start you learning. Try this:

1. Set NAME for the Damsel unit to Damsel1.

2. Place ANOTHER Damsel unit somewhere else and name her Damsel2.

3. Change the init for your player to this:

nul = [player, Damsel1] execVM "myScript.sqf";

4. Change myScript.sqf to this:

_personOne = _this select 0;
_personTwo = _this select 1;

_personOne setPos (getPos _personTwo);

Then see if you can figure out what to change to move the player to Damsel2. Then see if you can figure out how it works.

And TankBuster is totally correct, I'm learning something everyday even after years. :)

  • Like 1

Share this post


Link to post
Share on other sites

Oh jeussss!

I did not realise you needed to name, I thought it would take the Arma classname! Well I learned something today.

So would that be what people refer to as the objectname?

kylania, going to try your exercise in a bit (just about to leave for my drive home).

Thanks again all.

Share this post


Link to post
Share on other sites

Correct, the classname is a string (so something within " ", like "Damsel1") and is used for things like:

myGF = group player createUnit ["Damsel1", Position player, [], 0, "FORM"];

That would create a new Damsel unit at your location and join her to your group. You would then be able to refer to her as myGF in other commands such as:

myGF assignAsCargo myCar;
[myGF] orderGetIn true;

That would tell your new girlfriend to get in the car named myCar.

In both examples myCar and myGF would be objects instead of the string that "Damsel1" would be.

Share this post


Link to post
Share on other sites
Notice you're not actually naming the Damsel in there. You'd want to have "Damsel1" in the Name field of her Edit Unit screen. This might look a little complicated but it'll start you learning. Try this:

1. Set NAME for the Damsel unit to Damsel1.

2. Place ANOTHER Damsel unit somewhere else and name her Damsel2.

3. Change the init for your player to this:

nul = [player, Damsel1] execVM "myScript.sqf";

4. Change myScript.sqf to this:

_personOne = _this select 0;
_personTwo = _this select 1;

_personOne setPos (getPos _personTwo);

Then see if you can figure out what to change to move the player to Damsel2. Then see if you can figure out how it works.

And TankBuster is totally correct, I'm learning something everyday even after years. :)

Hmmm...

_personOne = _this select 0; // Selects the first array entry (passed on by _this) which would be '[b]player[/b]'
_personTwo = _this select 1; // Selects the second array entry which would be 'Damsel1'

_personOne setPos (getPos _personTwo); // Moves Player to the same location as [b]Damsel1[/b].

Now the only thing that confused me and also scared the crap of me was, on turning around while muttering ("where is she") I was faced with this freakshow..

2blWl.png

So how did Damsel2 get moved? Is it because they are part of the same unit (Civilian)?

For your exercise of how to move Damsel2, as far as I can see...

Change the init perhaps...

nul = [player, Damsel[b][color="#FF0000"]2[/color][/b]] execVM "myScript.sqf";

Or even extend the array:

nul = [player, Damsel1, Damsel2] execVM "myScript.sqf";

_personOne = _this select 0;
_personTwo = _this select 1;
_personThree = _this select 2;


_personOne setPos (getPos _personThree);

Edited by robot

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  

×