Problem with commanding a ship by script

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
madhax47
Posts: 3
Joined: Mon, 25. Apr 11, 13:26
x4

Problem with commanding a ship by script

Post by madhax47 » Mon, 1. Sep 14, 15:32

Hi scripters,
in the following script I tried to creat a menu to easily command my ships.
* ************************************************
* SCRIPT NAME: COSIN.nav.xml
* DESCRIPTION: COSIN navigation
*
* AUTHOR: Madhax47 DATE: 30 August 2014
* ************************************************
$text = sprintf: pageid=8911 textid=3, null, null, null, null, null
$menu = create custom menu array: heading=$text

add custom menu item to array $menu: page=8911 id=6 returnvalue='goto'
add custom menu item to array $menu: page=8911 id=7 returnvalue='dock'
add custom menu item to array $menu: page=8911 id=8 returnvalue='follow'
add custom menu item to array $menu: page=8911 id=9 returnvalue='go.gate'
add custom menu item to array $menu: page=8911 id=10 returnvalue='go.sec'
add custom menu item to array $menu: page=8911 id=11 returnvalue='jump'
add custom menu item to array $menu: page=8911 id=12 returnvalue='jump.goto'
add custom menu item to array $menu: page=8911 id=13 returnvalue='jump.dock'

label.menu:
= wait 5 ms
$text = sprintf: pageid=8911 textid=1, null, null, null, null, null
$ans = open custom menu: title=$text description='' option array=$menu

if $ans == -1
return null

else if $ans == 'goto'

$ship = [THIS]-> get user input: type=[Var/Ship owned by Player], title='Waehlen Sie Ihr Schiff'
$sector = $ship-> get sector
$position = [THIS]-> get user input type=[Var/Sector Position], title='Waelen Sie die Position', sector=$sector
$pos.x = $position-> get x position
$pos.y = $position-> get y position
$pos.z = $position-> get z position
$command = $ship-> move to position: x=$pos.x y=$pos.y z=$pos.z with precision 2000 m

else if $ans == 'dock'
$ship = [THIS]-> get user input: type=[Var/Ship owned by Player], title='Waehlen Sie Ihr Schiff'
$sector = $ship-> get sector
$station = [THIS]-> get user input type=[Var/Station/Carrier to dock at], title='Waelen Sie die Station', sector=$sector
$command = $ship-> fly to station $station

else if $ans == 'follow'
* $follow=[THIS]-> call script `COSIN.property` :

else if $ans == 'go.sec'
* $go.gate=[THIS]-> call script `COSIN.property` :

else if $ans == 'go.gate'
* $go.gate=[THIS]-> call script `COSIN.property` :

else if $ans == 'jump'
* $jump=[THIS]-> call script `COSIN.property` :

else if $ans == 'jump.goto'
* $jump.goto=[THIS]-> call script `COSIN.property` :

else if $ans == 'jump.dock'
* $jump.dock=[THIS]-> call script `COSIN.property` :

end
goto label label.menu:

return null
The menu itself worked without problems, but my ships won't accept the commans move to position and fly to station.
I hope someone can help me with my problem.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Mon, 1. Sep 14, 16:24

these are commands you use in a actual Fly To-Script which has to execute them in a loop until they return success (or fail). you have to use start script and call a move to/fly to Script there, which take care of the stuff necesary around those commands.
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

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

Post by X2-Illuminatus » Mon, 1. Sep 14, 19:26

Also you're using the commands for getting the position(s) wrongly.

Code: Select all

$position = [THIS]-> get user input type=[Var/Sector Position], title='Waelen Sie die Position', sector=$sector
$pos.x = $position-> get x position 
$pos.y = $position-> get y position 
$pos.z = $position-> get z position
The first command already gives you an array containing the coordinates x, y and z as well as the sector. While the get x/y/z position commands are to be used with an actual object, e.g. to get the single position coordinates of a ship or station. The way it is used now, $pos.x, $pos.y and $pos.z will always be 0.
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!

madhax47
Posts: 3
Joined: Mon, 25. Apr 11, 13:26
x4

Post by madhax47 » Mon, 1. Sep 14, 20:46

Thank you so much. Now I figured out how to do it.

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

Post by Cycrow » Tue, 2. Sep 14, 11:52

its also a good idea to call the scripts rather than using those commands directly

like !move.movetostation

Post Reply

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