Home   Help Search Login Register  

Author Topic: Moving units without waypoints  (Read 1259 times)

0 Members and 1 Guest are viewing this topic.

Rocko Bonaparte

  • Guest
Moving units without waypoints
« on: 01 Dec 2004, 04:44:03 »
I've seen some work done in assigning movement to units based on code, and not by using fixed waypoints.  The general consenus has been to make missions more flexible by making waypoints dynamic.

I found a tutorial for assigning units to move to certain positions using markers, and there were some waypoints involved as well.  It wasn't what I was hoping.  I had already written a script for moving a unit along some path.  The idea was that it would ultimately turn into a state machine, and the unit would change its mission as different conditions changed.  For now, though, it was just cycling a sequence.  

Here's a simplified version of what I had written:
Code: [Select]
_player_name = _this select 0

_player = call format["%1",_player_name]
_pos = "Logic" CreateVehicle [9632.477539,29.834999,3865.032227]

#Move1
_pos setPos [9632.477539,29.834999,3865.032227]
_player move (position _pos)
hint "Told target to move"
@((_player distance _pos) < 2.0)

#Move2
hint "Moving to second target"
_player doMove [9708.595703,29.834999,3865.032227]
_pos setPos [9708.595703,29.834999,3865.032227]
@((_player distance _pos) < 2.0)

#Move3
_player doMove [9709.749023,29.834999,3936.538574]
_pos setPos [9709.749023,29.834999,3936.538574]
@((_player distance _pos) < 2.0)

#Move4
_player doMove [9627.863281,29.834999,3933.078613]
_pos setPos [9627.863281,29.834999,3933.078613]
@((_player distance _pos) < 2.0)

goto "Move1"

I have a few different ways of moving shown above, with none of them working.  I assign a solider as its own group to this script in init.  The unit will just stand around, although I get the message "Told target to move." I've tried commandMove, doMove, and just plain move.  I've been wrapping the position in an object because the move commands don't really like that array.  If the script got any further than the first move, it should actually error.  Still, you should be able to see what I am trying to do.

It doesn't seem like I fully understand how the move commands actually work.  The OFP comref is lacking in that regard--the only distinction it seems to make above them is how they are relayed over the radio.

Can I use the code above in a certain way?  Do I NEED markers and waypoints?

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Moving units without waypoints
« Reply #1 on: 01 Dec 2004, 05:03:28 »
i think your problem is right here:
Quote
_player = call format["%1",_player_name]
you are turning the units name into a string, which can't be used with the move commands (i think)

i would eliminate that line, and change every _player into _player_name

and that should work
« Last Edit: 04 Dec 2004, 00:28:01 by Triggerhappy »

Rocko Bonaparte

  • Guest
Re:Moving units without waypoints
« Reply #2 on: 01 Dec 2004, 06:37:11 »
I can't test it right now, but I can already tell that makes me worried.  I'm going through all that trouble because the script will ultimately be for multi-player.  The player that is the subject of that script will inevitably die and respawn.  Given that circumstance, would using _player_name still work?

Rocko Bonaparte

  • Guest
Re:Moving units without waypoints
« Reply #3 on: 03 Dec 2004, 03:09:49 »
i think your problem is right here:you are turning the units name into a string,
I just tried this and it turns out I am not turning the unit into a string; I'm turning the string into a unit.  doMove complains that I am using a string if I use _player_name as my object.  Needless to say, the person still won't move.

Edit: I have the target of the script be me now.  I'm assuming I'd get a yellow box with "MOVE" printed by it on my HUD when the move command was given.  It doesn't happen; whether I use move, doMove, or commandMove.  

Something that may be important to know is I'm passing the name of the unit into my script.  I wonder if it's something just basic.  I tested killing a person in front of my by setting their damage to maximum in the script, and it looks like the script is getting its targets correctly.  People just won't move when told to for something reason.
« Last Edit: 03 Dec 2004, 04:15:10 by Rocko Bonaparte »

Offline Artak

  • The old beanbag shaker
  • Former Staff
  • ****
  • You want to talk about it, yes?
    • OFP Team Finlanders
Re:Moving units without waypoints
« Reply #4 on: 03 Dec 2004, 09:47:30 »
Whaaat?

Try changing

_player_name = _this select 0
to
_player = _this select 0


_player = call format["%1",_player_name]
to
_player = call format["%1",name _player]


_player move (position _pos)
to
_player move getpos _pos
Not all is lost.

Rocko Bonaparte

  • Guest
Re:Moving units without waypoints
« Reply #5 on: 04 Dec 2004, 01:20:38 »
OK here's what I tried:
Code: [Select]
? not local Server : exit
_player = _this select 0

_player = call format["%1", name _player]

_pos = "Logic" CreateVehicle [9632.477539,29.834999,3865.032227]

#Move1
_pos setPos [9632.477539,29.834999,3865.032227]
_playerobj move (getpos _pos)
However the "call format" line generates the error "Error name: Type String, expected Object."

If I just take it out and use:
Code: [Select]
? not local Server : exit
_player = _this select 0

_pos = "Logic" CreateVehicle [9632.477539,29.834999,3865.032227]

#Move1
_pos setPos [9632.477539,29.834999,3865.032227]
_player move (getpos _pos)
There is no error, but the target unit doesn't move either.  Just stands there with his gun out.

edit: Using "_player" in last line, not "_playerobj"
« Last Edit: 04 Dec 2004, 03:01:39 by Rocko Bonaparte »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Moving units without waypoints
« Reply #6 on: 04 Dec 2004, 01:41:03 »
Where is _playerobj defined?

I can't see it mentioned in the script. apart from the last line.

Also, you probably don't need the line:

_pos setPos [9632.477539,29.834999,3865.032227]

because _pos is already at this position when you created it with this line:

_pos = "Logic" CreateVehicle [9632.477539,29.834999,3865.032227]


Planck
I know a little about a lot, and a lot about a little.

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Moving units without waypoints
« Reply #7 on: 04 Dec 2004, 01:50:32 »
Almost forgot........the move command is for moving groups, try domove instead.


Planck
I know a little about a lot, and a lot about a little.

Rocko Bonaparte

  • Guest
Re:Moving units without waypoints
« Reply #8 on: 04 Dec 2004, 03:10:10 »
It looks like you caught something.  I've narrowed the script down to just this:
Code: [Select]
_player = _this select 0

_pos = "Logic" CreateVehicle [9632.477539,29.834999,3865.032227]

_player doMove (getpos _pos)
And it complains that _player is a string, not an object.

I call this in my init.sqs:
Code: [Select]
["TestJeep"] exec "waypoints.sqs"

And "TestJeep" is referred to my mission here:
Code: [Select]
      class Item1
      {
         side="WEST";
         class Vehicles
         {
            items=1;
            class Item0
            {
               position[]={9662.691406,29.834999,3908.917236};
               id=1;
               side="WEST";
               vehicle="SoldierWB";
               leader=1;
               skill=0.600000;
               text="TestJeep";
            };
         };
      };
It looks like I have a more fundamental problem here -- properly passing that value in.  As a string, I've been able to set the damage of the thing and have it die, but it doesn't want to accept the move command.  I'm guessing some commands are more flexible than others.  What can I do?

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Moving units without waypoints
« Reply #9 on: 04 Dec 2004, 04:24:42 »
in the mission file everything has quotes around it. get rid of the quotes when you exec the script

"This" is a string
This isn't

Rocko Bonaparte

  • Guest
Re:Moving units without waypoints
« Reply #10 on: 04 Dec 2004, 05:07:40 »
Do you mean to get rid of them in init, or in the mission?  First, I tried:
Code: [Select]
[TestJeep] exec "waypoints.sqs"That didn't work, so I tried taking the quotes of the text field.  The soldier still just stands there.  I tried doMove and move, and neither worked.  :-\

BTW, "TestJeep" right now is a solider, not a jeep.



Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Moving units without waypoints
« Reply #11 on: 04 Dec 2004, 05:34:01 »
unless you are working in the mission.sqm file, names of units are not in quotations.
quotes words are a string, which is used for hints, titletext, sidechats

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Moving units without waypoints
« Reply #12 on: 04 Dec 2004, 14:21:09 »
So, your soldier is named TestJeep in his name field?

Is TestJeep the player, or is he an AI soldier?

If he is the player, of course, you can't force him to move anywhere.



Planck
I know a little about a lot, and a lot about a little.

Rocko Bonaparte

  • Guest
Re:Moving units without waypoints
« Reply #13 on: 05 Dec 2004, 00:18:51 »
So, your soldier is named TestJeep in his name field?

Is TestJeep the player, or is he an AI soldier?

If he is the player, of course, you can't force him to move anywhere.



Planck
TestJeep is an AI soldier.  I tried it on the player as well to see if anything came up on the HUD.  Nothing showed up using commandMove, doMove, or move.

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Moving units without waypoints
« Reply #14 on: 05 Dec 2004, 02:56:40 »
I think your height value in this line is a little suspect:

_pos = "Logic" CreateVehicle [9632.477539,29.834999,3865.032227]

The second value in that list looks more like a reasonable height value.

Try swapping them about.


Planck
I know a little about a lot, and a lot about a little.