Script question about ''get ship array from sector/ship/station'' command

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

Post Reply
qwizzie
Posts: 562
Joined: Thu, 1. Jun 06, 12:17
x4

Script question about ''get ship array from sector/ship/station'' command

Post by qwizzie » Mon, 20. May 13, 23:13

I'm using below scriptcode to get an array back which i use to color the stations and ships IS. Plan is to recue this script in MD on a regular basis so these ships and stations get updated automatically without stressing the engine too much as its only an array for IS. I'm aware the ''get ship array from sector/ship/station'' command only works in X3 : AP and is rather new.

Problem i have is how to sort the array into different race objects (ships / stations). lets say for example i just want the Argon ships and stations ending up in the array, can that be done ? or maybe the array can be split into more arrays to store the different race objects?

Any tips or advice would be helpfull.

qwizzie

Code: Select all

$PageID = 9921
load text: id=$PageID
$playership = [PLAYERSHIP]
$sector = $playership-> get sector
$array.ship = $sector-> get ship array from sector/ship/station
$size = size of array $array.ship
while $size > 0
dec $size
$ship = $array.ship[$size]
$is.renamed = $ship-> get local variable: name='AS.Is.Renamed'
if $is.renamed != [TRUE]
$ship-> set local variable: name='AS.Is.Renamed' value=[TRUE]
$old.name = $ship-> get name
$new.name = sprintf: pageid=$PageID textid=100, $old.name, null, null, null, null
$ship-> set name to $new.name
end
do if $size == ($size / 20) * 20
= wait 100 ms
$array.station = $sector-> get station array from sector
$size1 = size of array $array.station
while $size1 > 0
dec $size1
$ship1 = $array.station[$size1]
$is.renamed1 = $ship1-> get local variable: name='AS.Is.Renamed1'
if $is.renamed1 != [TRUE]
$ship1-> set local variable: name='AS.Is.Renamed1' value=[TRUE]
$old.name1 = $ship1-> get name
$new.name1 = sprintf: pageid=$PageID textid=100, $old.name1, null, null, null, null
$ship1-> set name to $new.name1
end
do if $size1 == ($size1 / 20) * 20
= wait 100 ms
end
end
return null

Edit : small correction to code above

User avatar
X2-Illuminatus
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 24963
Joined: Sun, 2. Apr 06, 16:38
x4

Post by X2-Illuminatus » Mon, 20. May 13, 23:46

qwizzie wrote: I'm aware the ''get ship array from sector/ship/station'' command only works in X3 : AP and is rather new.
What makes you think so? The command exists at least since X3:R. And I used it without problems in X3TC (probably also X3R) before.
qwizzie wrote:Problem i have is how to sort the array into different race objects (ships / stations). lets say for example i just want the Argon ships and stations ending up in the array, can that be done ?
Simply check for the owner of the ship/station (see the General Object Commands) and either remove those items that are not owned by Argons or add them to a second array.
Nun verfügbar! X3: Farnham's Legacy - Ein neues Kapitel für einen alten Favoriten

Die komplette X-Roman-Reihe jetzt als Kindle E-Books! (Farnhams Legende, Nopileos, X3: Yoshiko, X3: Hüter der Tore, X3: Wächter der Erde)

Neuauflage der fünf X-Romane als Taschenbuch

The official X-novels Farnham's Legend, Nopileos, X3: Yoshiko as Kindle e-books!

qwizzie
Posts: 562
Joined: Thu, 1. Jun 06, 12:17
x4

Post by qwizzie » Tue, 21. May 13, 00:13

thanks for yr reply, was working with X-Studio which gave that warning... except i mixed-up the command it was applicable to. Appearently it was still in my head when i was writing this post.

Its in fact for another command :

RetVar/IF >> << RefObj>> get local variable : name=<<Var/String>>
**only albion prelude 2.5.3 or newer will allow you to store values in sectors**

2.5.3 Update (22/01/2013)
•Script engine supports local variables being applied to sectors

Thanks for your tip, will explore it some more. Was already experimenting with the remove element from array .. at index .. command. Couldnt get it to work. Will read up on that part of scripting some more.

Good to know that if i can get this sorted, it can be used for both TC and AP.

qwizzie

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22227
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow » Tue, 21. May 13, 09:57

if your going to remove elements from the array, make sure you iterate backwards

Post Reply

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