[SCRIPT] Help me make a quick extension script to ADS Real Wings...

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
Overwatch
Posts: 21
Joined: Wed, 18. Jun 14, 19:29

[SCRIPT] Help me make a quick extension script to ADS Real Wings...

Post by Overwatch » Thu, 10. Jul 14, 12:47

I've been poking around in scripts for the past week, and I think it's time I write one of my own to shape the game a bit more to my liking. I'm using Anarkis Defense System - Real Wings Edition but I'd like to make a companion script to make managing certain situations faster.

Let me explain a bit more. Right now I'm playing with 1x M6 as my player ship + 2x TMs with 4x M3s each.

Right now, to begin combat I need to:
  1. Hit the ADS config Key
  2. Select my first TM
  3. Expand the "Command Panel"
  4. Click "ADS: Send Defensive Wing" which opens the universe map
  5. Select my current sector
  6. Select my player ship
  7. Click "Launch Wing"
  8. Scroll Down to the list of ADS Carriers
  9. Select my second TM
  10. Expand the "Command Panel"
  11. Click "ADS: Send Defensive Wing" which opens the universe map
  12. Select my current sector
  13. Select my player ship
  14. Click "Launch Wing"
  15. Close the window
which is unacceptable if I have 5 seconds till a dogfight erupts.

What I'd like to happen is more like this:
  1. Pre combat
    • Have some way to designate all my "Tactical" carriers.
    • A menu would be OK, but so would a hot-key with the carrier selected.
    • I'm guessing these would get stored in an array? I'm still VERY new to how the X3 script engine works.
  2. During, or right before combat
    • Hit 1 key and have all my "Tactical" carriers launch defensive wings with my player ship as the target.
  3. Post combat
    • Hit 1 key and have all my "Tactical" carriers recall their defensive wings.
Up to this point, I have been sucessful modifying scripts to work with eachother, or to fix some small errors enough so that they seem to work properly. I have not yet written something from scratch though, so I'm a little lost about where to start.

Can someone point me in the right direction?

I'm guessing I need to know these things:
  1. How to bind a Hotkey to call a script.
  2. How to define an array
  3. How to assign ships to that array
  4. How to remove specific ships from the array, or how to delete it and start again
  5. How ADS formats its script calls.
  6. How to call the "Send Defensive Wing" command, for all ships in the above array, with my player ship as the predefined target
  7. How to call the "Dock all Ships" command for each ship in the above array.

User avatar
Jack08
Posts: 2993
Joined: Sun, 25. Dec 05, 10:42
x3tc

Post by Jack08 » Thu, 10. Jul 14, 13:03

  1. How to bind a Hotkey to call a script.
  2. How to define an array
  3. How to assign ships to that array
  4. How to remove specific ships from the array, or how to delete it and start again
  5. How ADS formats its script calls.
  6. How to call the "Send Defensive Wing" command, for all ships in the above array, with my player ship as the predefined target
  7. How to call the "Dock all Ships" command for each ship in the above array.

If you need someone to tell you how to do all of that, wouldn't it be better if you started with something more simple, so you can learn how the X3 engine works?

Ill fill in some of the basics:
The MSCI is garbage collected, when a variable no longer has any references its freed automatically... allocating an array is a one line command in general commands. Array iteration uses a basic forward or reverse loop with a integer counter counting the size of the array and Array manipulation commands are listed under the same location as the allocation command.

a very basic reverse iteration loop would be the following:

Code: Select all

$shipList.Size = size of array $shipList
while $shipList.Size
  dec $shipList.Size = 
  $cShip = $shipList[$shipList.Size]

  * Do somthing with ship
  START $cShip->call script 'SCRIPT TO DO SOMTHING' : arg1='Now!'
end
[ external image ]
"One sure mark of a fool is to dismiss anything that falls outside his experience as being impossible."
―Farengar Secret-Fire

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

Post by Joubarbe » Thu, 10. Jul 14, 14:30

And if you don't want this kind of nonsense, go with X-Studio. It has a nice "for each" macro.

Indeed these are big questions. If you have no experience in coding at all, then you should aim for a smaller script. A lot of answers can (and are) found by exploring existing scripts.

Overwatch
Posts: 21
Joined: Wed, 18. Jun 14, 19:29

Post by Overwatch » Thu, 10. Jul 14, 15:57

Yeah I'm using X-studio already. It was the only way I could stand to work on scripts that were embedded in XML for absolutely no reason.

I know enough Java, Object C, X86 Assembly, ARM Assembly to cobble together what I need usually, but the X scripting syntax looks like crazy talk. Does it really use phrases with spaces as single arguments/function calls/object properties?

Code: Select all

$ship-> set destination to null
Really?

I'm guessing that in a real programming language that would read

Code: Select all

this.ship.destination = NULL;
Is there somewhere I can go and read the API?

User avatar
Jack08
Posts: 2993
Joined: Sun, 25. Dec 05, 10:42
x3tc

Post by Jack08 » Thu, 10. Jul 14, 16:22

The API is entirely infront of you within X Studio - i think that the problem is your looking at them as if they are objects and individual statements, they are not.

with the exception of the dynamic expression command (the one that uses conditionals such as if and while, and handles operators) - each line is a single command.

For example "$ship->set destination to null"
While you could technically read this as if it was a list of instructions in an high level programming language (somthing silly like VB) - its not

"set" "destination" "=" "null" is not how this is seen by the compiler, or the game

"<RefObj>" "set destination to" "null" is how this gets seen, "set destination to" would be, in C, somthing like "Ship.setDestinationTo(NULL)"

Evrey command in the game is listed in the "Commands" pane in X-Studio, we are dealing with a language closer to assembly in nature then much else, think of the commands as opcodes. The actual MSCI is a virtual stack machine.

-------

Now, the dynamic expression command... this one is slightly diffrent, it takes an infinate amount of variables and operators, euch as

$Value = $A + $B / $C + ($A/$X)
but you cannot embed other commands into this, this is invalid and wont compile:
$Value = $Ship->get max hull / 100

Some commands have a <RetVar/IF> return value, which allows you to do this:

while $Ship->exists
end

do if $Ship->exists

etc, however this is not part of the dynamic expression command, but rather the specific command - and if it supports a conditional return value.
[ external image ]
"One sure mark of a fool is to dismiss anything that falls outside his experience as being impossible."
―Farengar Secret-Fire

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

Post by Nicoman35 » Thu, 10. Jul 14, 17:26

If I get you right, you would need some hotkey with the functionality: UHOH, the odds get overwhelming here - THEY BEAT THE SHIT OUT OF ME! Carriers, HEEEEELP!!!
And there should one or more carriers be assigned to send in reinforcements in case of your distress call...Right?

Overwatch
Posts: 21
Joined: Wed, 18. Jun 14, 19:29

Post by Overwatch » Thu, 10. Jul 14, 19:18

Kind of, but less panicky. I'm really just trying to streamline the small unit tactics play. Right now I'm doing something like:
  1. Get mission
  2. Jump myself to a sector, TMs follow me a few moments later on their own
  3. Unpack the carriers
  4. Murder the baddies
  5. Pack everyone back up
  6. Look for more missions
I'm trying to have my 2 TMs as my full time escorts. I don't just use them when i'm in trouble. I launch my wings every single fight because I don't bother to chase 2-3 M5s.

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

Post by Nicoman35 » Thu, 10. Jul 14, 20:00

Then it would be better, if you make your little add on like you want it to be :).

If you like, I could give you advice on the structure of the mod, what script does what and where you could do some key alterations / add ons - like adding hotkeys, changing relevant menus and so on.

Let's begin from the start:

The very first script, that is loaded when you start or reload a game, is setup.anarkis.acc (all scripts beginning with setup.... will be loaded).
Inside of the setup script, you find:

Code: Select all

= [THIS]-> call script 'anarkis.acc.hotkey.install' : page.id=$page.id
This is the script responsible for installing the ADS hotkeys.
Right click on this line and open anarkis.acc.hotkey.install':

Code: Select all

$st = read text: page=$page.id id=600
$hotkey.clear = register hotkey $st to call script 'anarkis.acc.hotkey.cmd.clear'
$st = read text: page=$page.id id=601
$hotkey.dockall = register hotkey $st to call script 'anarkis.acc.hotkey.cmd.dockall'
$st = read text: page=$page.id id=602
$hotkey.attack = register hotkey $st to call script 'anarkis.acc.hotkey.cmd.attack'
$st = read text: page=$page.id id=603
$hotkey.defend = register hotkey $st to call script 'anarkis.acc.hotkey.cmd.defend'
$st = read text: page=$page.id id=604
$hotkey.manage.call = register hotkey $st to call script 'anarkis.ads.comm.manage.call'
dim $hotkeys = $hotkey.clear, $hotkey.dockall, $hotkey.attack, $hotkey.defend, $hotkey.manage.call
set global variable: name='anarkis.acc.hotkey' value=$hotkeys

return null
The first line defines how the hotkey will be named, by referring id 600 in the t file 8510:

Code: Select all

<t id="600">\033RADS:\033X Clear Sector</t>
The second line defines which script will be called when the hotkey is pressed: 'anarkis.acc.hotkey.cmd.clear'

The same procedure is done for all other ADS hotkeys.
These two lines at the end of the script:

Code: Select all

dim $hotkeys = $hotkey.clear, $hotkey.dockall, $hotkey.attack, $hotkey.defend, $hotkey.manage.call
set global variable: name='anarkis.acc.hotkey' value=$hotkeys 
Will store our hotkeys in an array, and the array in a global variable (good in case we later neeed to e.g. uninstall the hotkeys. Have a look at the script called a few lines later in the setup script:

Code: Select all

= [THIS]-> call script 'anarkis.acc.hotkey.uninstall' :
for this purpouse).

And that's hole magic regarding hotkeys.

If you need further advice, you will have to ask me precisely, otherwise I would have to write a book here...;)

Post Reply

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