Add marines back to the playership using a local var

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Add marines back to the playership using a local var

Post by Joubarbe » Mon, 30. Dec 13, 17:28

Hi,

I've spent 3 hours on a single line and it's starting to get boring...

Code: Select all

if [PLAYERSHIP] -> is docked
  $Station = [PLAYERSHIP] -> get environment
  $IsStationHasBeenExpanded = $Station -> get local variable:   name='XM_HasBeenExpanded'
  $StationPCMarines = $Station -> get local variable:   name='XM_PCMarines'
  $StationNbOfMarines = size of array $StationPCMarines
  if $StationNbOfMarines > 0 AND $IsStationHasBeenExpanded == [TRUE]
  $FreePlacesForMarines = [PLAYERSHIP] -> free space for marines
  if $FreePlacesForMarines >= $StationNbOfMarines
    $Station-> send incoming message: text=$MessageMarinesOnBoard temporary=[TRUE]
    for each $PCMarine in array $StationPCMarines using counter $CountStationMarines
      = $PCMarine -> add passenger to ship [PLAYERSHIP]
      remove element from array $StationPCMarines at index $CountStationMarines
    end
    $Station -> set local variable: name='XM_PCMarines' value=$StationPCMarines
    end
  end
end
The line is :

Code: Select all

= $PCMarine -> add passenger to ship [PLAYERSHIP]
In this script, I've previously stored an array of marines into a station ("XM_Marines"). This code will remove elements from the array as it should, but will not add passengers/marines to the [PLAYERSHIP] - which is a TM in that case (I've also tried create passenger without success). What is going on ... ?

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Mon, 30. Dec 13, 18:13

Have you tried it with [PLAYERSHIP] in space (not docked)?

Nicoman35
Posts: 681
Joined: Thu, 17. Nov 05, 13:12
x3tc

Post by Nicoman35 » Mon, 30. Dec 13, 18:24

In ADS, I use this line to add passengers to a ship:

Code: Select all

$passenger = [THIS]-> create passenger in ship: name=$p.name race=$race voice=$voice face=$face

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Mon, 30. Dec 13, 18:34

Not working in space either.

@Nicoman35 : I want to retrieve a list of already-created marines. However, I even tried to create a passenger that way, and that won't work. (I'm sure that the game goes inside the "for each" loop)

zanzal
Posts: 309
Joined: Sat, 15. Sep 12, 07:42
x3tc

Post by zanzal » Mon, 30. Dec 13, 18:37

Here is an idea, add something like:

Code: Select all

$sub = $PCMarine -> get subtype
$main = $PCMarine -> get maintype
$msg = sprintf: fmt='%s mt: %s sub: %s', $PCMarine, $main, $sub, null, null
display subtitle text: text=$msg duration=4000 ms
=wait 4000 ms
Just to make sure your $PCMarine is what you think it is.. Sorry though I can't offer any advice on the command add passenger to ship. I've not used it with Marines but I would suspect it should work and would want to make sure that $PCMarine is a valid passenger

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Mon, 30. Dec 13, 18:39

With [PLAYERSHIP] in space, use:

= [PLAYERSHIP]-> catch ware object $marine

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Mon, 30. Dec 13, 18:49

Hmm it's an "unknown object" so that may explain what it doesn't work...

I have no idea why. The declaration of the array is :

Code: Select all

$PCMarines = [PLAYERSHIP] -> get marines array
$StationPCMarines = $Station -> get local variable: name='XM_PCMarines'
....
for $x = 0 to $CountMarinesRef step 1
  $Marine = $PCMarines[$x]
  if is marine: passenger/astronaut = $Marine 
    append $Marine to array $StationPCMarines
    = $Marine -> destroy passenger
  end
end
$Station -> set local variable: name='XM_PCMarines' value=$StationPCMarines
The array size is always good. Probably something I missed in that piece of code ?

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Mon, 30. Dec 13, 18:52

Well, you are adding the marine to the array then immediately killing the marine.

So the pointer in the array points to... nothing.
  • (Catch ware object works. I use it in the Marines Repair Target hotkey of Marine Repairs and Training.)

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Mon, 30. Dec 13, 18:58

Damn I always forgot that arrays are pointers...

So how can I do what I want to do ? Destroy the passenger in the Playership, then store it into the station, then retrieve it ?

I want to simulate the fact that the marine goes into the station to do some work. So it must be "destroyed" from the playership.

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Mon, 30. Dec 13, 19:05

If the [PLAYERSHIP] does not have to be docked, then just use "Catch ware object". There is no need to destroy the marine because he will be moved into the ship.

If you need for [PLAYERSHIP] to be docked, then you will have to make the movement in multiple steps. You could spawn a temporary TP, "catch" the marines into the TP, dock the TP, then transfer the marines to the TM (using "add passenger"). Then destroy the TP. Maybe. I have never tried to do it with a docked ship, so you may have to experiment a bit.

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Mon, 30. Dec 13, 19:17

I'm not sure to be clear or to understand.

What I need is the Playership to dock at a station with 8 marines. Then the 8 marines are stocked into the station for 1 hour, after which, the Playership comes back and takes back his 8 same marines. So at some point, they have to disappear from the Playership's cargo. I don't see how "catch ware object" can help me here.

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Mon, 30. Dec 13, 19:21

It cannot. "Catch ware object" is for ships in space.

Try "add passenger" while docked. I have not tried it myself.

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Mon, 30. Dec 13, 19:29

But that's not what I'm asking :)

How can you destroy the marines into the playership with these pointers ? Do I need to make another dummy ship to stock them ? That's absurd !

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Mon, 30. Dec 13, 19:33

Forget the dummy ship. I did not understand what you were trying to do.

Use your original code (above). Except: Do not destroy the marines!

If that does not work, then look at Lucike's "Personnel Transport" to see how he does it.

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Mon, 30. Dec 13, 19:38

Ok, but if I do not destroy them, they will stay in the Playership's cargo :)

And I want them out, those ignorant bastards !!



(too much code for today)

zanzal
Posts: 309
Joined: Sat, 15. Sep 12, 07:42
x3tc

Post by zanzal » Mon, 30. Dec 13, 19:40

Code: Select all

 = $Marine -> destroy passenger 
You killed the marine.. murder!

No really what you probably want to do is create a ship somewhere in the x universe at some far off location (x=10000000 y=0 z=0) and move the marine to that ship... Don't make the ship owned by the player and don't assign a race or a pilot. (race=null)

Move the passengers to the holding ship and then store a reference to the ship object instead of an array.

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Mon, 30. Dec 13, 19:43

Try it.

The marines should *move* to the ship that you choose. Destroying them should be necessary only when you use "create passenger".

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Mon, 30. Dec 13, 19:44

Grrr I don't like that idea :)

But if that's the only way....

zanzal
Posts: 309
Joined: Sat, 15. Sep 12, 07:42
x3tc

Post by zanzal » Mon, 30. Dec 13, 19:46

yes it is a cheesy hack, but trust me, you'll get it to work and move on and forget you even had to do it that way ;)

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Mon, 30. Dec 13, 20:03

Joubarbe wrote:Grrr I don't like that idea
Which idea? And why not?

Just use exactly the code that you posted originally. But do not destroy the marines. That should *move* the marines.

Only "create marine" makes a copy which requires destroying the original.
  • (Forget the dummy ship. If you *do* need to destroy marines, then do it after you are done moving them. But it should not be necessary to destroy marines at all.)

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”