Binding hotkey to "launch all marines"
Moderators: Moderators for English X Forum, Scripting / Modding Moderators
-
- Posts: 384
- Joined: Sun, 13. Dec 15, 07:15
Binding hotkey to "launch all marines"
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)?
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)?
- ubuntufreakdragon
- Posts: 5195
- Joined: Thu, 23. Jun 11, 14:57
You only need 10 lines of Code to do the job. an a small textfile
a small setup script
and a small launchscript: "my.marine.hotkey"
btw. here is list of all comands+documentation: http://forum.egosoft.com/viewtopic.php?t=286349
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
Code: Select all
$target= get player tracking aim
Start Playership -> call script !ship.cmd.launchmarines.pl target= $target
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
XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist
- X2-Illuminatus
- Moderator (Deutsch)
- Posts: 24962
- Joined: Sun, 2. Apr 06, 16:38
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.fireanddream wrote:The hotkey worked all right but aren't we suppose to input more variables?
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.
In this case, you could easily leave the textfile away and borrow text from the main textfile.and a small 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!
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!
- ubuntufreakdragon
- Posts: 5195
- Joined: Thu, 23. Jun 11, 14:57
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
XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist
-
- Posts: 384
- Joined: Sun, 13. Dec 15, 07:15
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:
ubuntufreakdragon, what's the purpose of that?
However, I don't understand the first part of the code:
Code: Select all
$hotkey.id = get global variable name= "marine.hotkey.id"
- ubuntufreakdragon
- Posts: 5195
- Joined: Thu, 23. Jun 11, 14:57
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
XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist