[looking for] Script to collect/destroy unwanted satellites

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
Braekyn
Posts: 37
Joined: Mon, 4. Mar 13, 18:48
x3ap

[looking for] Script to collect/destroy unwanted satellites

Post by Braekyn » Mon, 4. Mar 13, 18:54

Exactly what it says: I' trying to find, or get some tips on how to make, a script to destroy, or send a ship to collect all satellites with a certain name. I've tried to script it myself, but never managed to get it to work correctly. There's far too many to do one at a time, but I'm not sure how to get loops to work correctly with the script editor.

User avatar
RoverTX
Posts: 1436
Joined: Wed, 16. Nov 11, 18:37
x4

Post by RoverTX » Mon, 4. Mar 13, 21:45

You might try looking at some of the salvage command's scripts out there. I believe one of them gives you the ability to pick up sats and jump beacons, but I could be wrong.

Braekyn
Posts: 37
Joined: Mon, 4. Mar 13, 18:48
x3ap

Post by Braekyn » Tue, 5. Mar 13, 00:14

Hmm, those still don't eliminate the need to select each satellite one by one to collect them. So, by a scriping method, I've tried adding all my satellites to an array (which works), but from there, I cannot for the life of me figure out a way to reference each object in the array to match it's name against a template. The "Find <var> in <array>" doesn't seem to work the way I expected it to. I guess I'm just used to a different language, but basically I want to do something like;

for(var/ship/satellite/Sat in player.ships)
>if(Sat.name=="Your Advanced Satellite")
>>Del(Sat)
>>Player.credits+=13476 //value of Adv.satellite
>else
>>continue

Or, make a list of all the satellites I own, check if they are named "Your Advanced Satellite", and if they are, destroy them and pay for them as if I sold them.

How would I go about doing that in the script editor?

User avatar
RoverTX
Posts: 1436
Joined: Wed, 16. Nov 11, 18:37
x4

Post by RoverTX » Tue, 5. Mar 13, 02:08

You would have to use the find all ships by race command, where the race would be player, then run through them, get their name, check it using the string equals command, and them move from there.

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

Post by X2-Illuminatus » Tue, 5. Mar 13, 10:00

Braekyn wrote:for(var/ship/satellite/Sat in player.ships)
>if(Sat.name=="Your Advanced Satellite")
>>Del(Sat)
>>Player.credits+=13476 //value of Adv.satellite
>else
>>continue
Braekyn wrote:How would I go about doing that in the script editor?
This way:

Code: Select all

001   $satellite.arr =  get ship array: of race Player class/type=Advanced Satellite
002   $size.satellite.arr = size of array $satellite.arr
003   while $size.satellite.arr
004   |dec $size.satellite.arr = 
005   |$satellite = $satellite.arr[$size.satellite.arr]
006   |$satellite.name = $satellite -> get name
007   |if $satellite.name == 'Your Advanced Satellite'
008   ||$satellite ->destruct: show no explosion=[TRUE]
009   ||add money to player: 13476
010   |end
011 @ |= wait 1 ms
012   end
013   return null
Download from mediafire.com

Some general notes: In the Script Editor there are only while-loops. To reference an object within an array you have to get that object from the array first. The "Find <var> in <array>" command just gives you the information, whether a certain value is stored within that array. That means, if the array contains ships, you can check, if a certain ship is stored in that array. Again, to reference an object and check its properties you would have to get that object from the array first.
Of course the name check (lines 6, 7 and 10) could be removed from my example above, if you want to destroy all of your advanced satellites.
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!

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

Post by Cycrow » Tue, 5. Mar 13, 10:52

you could also get the average cost of the Advanced satalite and use that instead of writing the price in manually.

Post Reply

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