Binding hotkey to "launch all marines"

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
fireanddream
Posts: 384
Joined: Sun, 13. Dec 15, 07:15
xr

Binding hotkey to "launch all marines"

Post by fireanddream » Sat, 9. Jan 16, 13:34

I love doing spacewalk boarding, simply because it's more fun than pressing L 30 times while running away.

Problem is, selecting your ship, command console, additional ship commands, launch all marines, select current target (no ship I meant to launch them toward the f**king sun, for Christ's sake!), menu diving while your target is heading toward you gun blazing can be (unnecessarily) stressful. So I want to bind a hotkey to it.

What I did:
$WOULDYOUJUSTDOIT = register hotkey 'launch all marines' to call script !ship.cmd.launchmarines.pl
return null

Never expected it to work. The hotkey worked all right but aren't we suppose to input more variables? Like, the baseship (usually the one we're in), the target (again, not the f**king sun)?

User avatar
ubuntufreakdragon
Posts: 5195
Joined: Thu, 23. Jun 11, 14:57
x4

Post by ubuntufreakdragon » Sat, 9. Jan 16, 15:39

You only need 10 lines of Code to do the job. an a small textfile
a small setup script

Code: Select all

load text: id = XXXX
skip if read text page= XXXX id=0 exists
return null
$hotkey.id = get global variable name= "marine.hotkey.id"
if not $hotkey
$name = read text page= XXXX id=1
$hotkey = register hotkey $name to call script my.marine.hotkey
set global value name= "marine.hotkey.id" value= $hotkey
end
return null
and a small launchscript: "my.marine.hotkey"

Code: Select all

$target= get player tracking aim
Start Playership -> call script !ship.cmd.launchmarines.pl target= $target
return null
btw. here is list of all comands+documentation: http://forum.egosoft.com/viewtopic.php?t=286349
My X3 Mods

XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist

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

Post by X2-Illuminatus » Sat, 9. Jan 16, 20:37

fireanddream wrote:The hotkey worked all right but aren't we suppose to input more variables?
When you call a script via a hotkey, then it runs globally (on null) without any chance for you to input variables via the arguments, which are defined in the script. That means that the initial arguments are not filled and, if the script is supposed to be run locally on an object, it won't have a reference object. Often it will be checked, whether the arguments and reference object exist. If that is not the case, the script will usually be cancelled directly. That is exactly what is happening here. First of all, "!ship.cmd.launchmarines.pl" asks for a ship as a target as an argument. If this argument is not filled, the first conditional statement fails and you're send directly to the 'exit'. Secondly, the reference object [THIS] always refers to the object the script currently runs on. Since a script started by a hotkey runs globally, [THIS] is null and all following checks with THIS will fail as well.
You can avoid this by calling a script getting you these needed pieces of information and start the actual boarding script then, as shown in ubuntufreakdragon's example.
and a small textfile
In this case, you could easily leave the textfile away and borrow text from the main textfile.
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!

User avatar
ubuntufreakdragon
Posts: 5195
Joined: Thu, 23. Jun 11, 14:57
x4

Post by ubuntufreakdragon » Sat, 9. Jan 16, 23:08

Ok if you use the vanilla text the setup script would look this way:

Code: Select all

$hotkey.id = get global variable name= "marine.hotkey.id"
if not $hotkey
$name = read text page= 2010 id=80
$hotkey = register hotkey $name to call script my.marine.hotkey
set global value name= "marine.hotkey.id" value= $hotkey
end
return null
My X3 Mods

XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist

fireanddream
Posts: 384
Joined: Sun, 13. Dec 15, 07:15
xr

Post by fireanddream » Sun, 10. Jan 16, 09:29

Thanks for all the help! Can't believe I didn't think of calling another script which input all the variables for the marine launching script...

However, I don't understand the first part of the code:

Code: Select all

$hotkey.id = get global variable name= "marine.hotkey.id"
ubuntufreakdragon, what's the purpose of that?

User avatar
ubuntufreakdragon
Posts: 5195
Joined: Thu, 23. Jun 11, 14:57
x4

Post by ubuntufreakdragon » Sun, 10. Jan 16, 14:59

if you don't check whether you already added the hotkey you will spam your controls tab with multiple hotkeys and there is no way to undo it if you don't know its id.
My X3 Mods

XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist

Post Reply

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