Scan all ships in sector

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

Irrehaare
Posts: 66
Joined: Sun, 15. Nov 15, 19:20
x3ap

Scan all ships in sector

Post by Irrehaare » Sat, 26. Mar 16, 13:35

Hi!

I've got simple question: is there a mod that would let me order M5 scout (or even better a wing of those) to scan all capital ships in sector for military purposes? So I'd know their loadouts.

After all it's a task that M5 (Scout fighter) is designed to do, isn't it?
“A mind is like a parachute. It doesn't work if it is not open.”

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

Post by Joubarbe » Sat, 26. Mar 16, 15:55

There is no such mod. But that's a good exercise for learning scripting in X3 :)

Irrehaare
Posts: 66
Joined: Sun, 15. Nov 15, 19:20
x3ap

Post by Irrehaare » Sat, 26. Mar 16, 15:58

So that is how it begins...
;P
“A mind is like a parachute. It doesn't work if it is not open.”

Joelnh
Posts: 429
Joined: Wed, 3. Mar 10, 00:12
x3tc

Post by Joelnh » Sun, 27. Mar 16, 23:26

here's a script you could start with.

http://forum.egosoft.com/viewtopic.php?t=284497

Irrehaare
Posts: 66
Joined: Sun, 15. Nov 15, 19:20
x3ap

Post by Irrehaare » Sun, 3. Apr 16, 19:51

Sooo I started trying to write it.
I'm trying to write in X-Studio and I think I'm beggining to undertand basics. However, I've hit a wall:

Is there a ship equivalent for command "is asteroid scanned"? Or if there isn't is there another way to check if $ship is scanned?

Writing such script without beeing able to check it sound quite difficult...
“A mind is like a parachute. It doesn't work if it is not open.”

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

Post by X2-Illuminatus » Thu, 7. Apr 16, 15:45

Irrehaare wrote:Is there a ship equivalent for command "is asteroid scanned"? Or if there isn't is there another way to check if $ship is scanned?
Afaik there isn't such a command, whereby I don't think that this is much of an issue. After all, the problem you're trying to solve is having many ships automatically scanned by your AI controlled ships, right? So you have a few prerequisites: First of all, the player most-likely won't issue this command, if they scanned many ships in the sector themself. Otherwise they probably sit in a capable ship already and could scan the remaining ships too.* Secondly, you will use relative fast ships for this task, for example the mentioned M5 class ships. Due to their speed, whether they scan a few ships, which have been scanned before, doesn't really matter for the overal duration of that scanning process. Thirdly, when your ships (i.e. those started with the dedicated command) scan a ship, you can set a local variable on that ship to mark it as being scanned. That way preventing that a ship is scanned more than once by different scouts.


*If you still want to cover this case, then you can ask the player what ship(s) they want to have scanned.
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!

Irrehaare
Posts: 66
Joined: Sun, 15. Nov 15, 19:20
x3ap

Post by Irrehaare » Thu, 7. Apr 16, 16:38

Thanks. I'll have to find our how to set this local variable though... But a least now I know what to look for ^^
“A mind is like a parachute. It doesn't work if it is not open.”

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

Post by Joubarbe » Thu, 7. Apr 16, 16:42

Code: Select all

$myShip -> set local variable name='isScanned' value=[TRUE]
Local variables can be applied to ships, stations and sectors. (and asteroids and gates in LU, if I'm not mistaken)

It's best to add a prefix to all your variables ; i.e: "myMod_isScanned", just to be sure that no other mods will use the same name.

EDIT : as a prerequisite, you'd also probably want to check if the ship is equiped with a scanner.

Irrehaare
Posts: 66
Joined: Sun, 15. Nov 15, 19:20
x3ap

Post by Irrehaare » Fri, 8. Apr 16, 14:57

Thanks.

Prerequisite were easy, I took them from MEMIA Autoscan I think...

One last question: if local variable is applied to ship as an element of an array, like:

Code: Select all

$ship.array[$i] -> set local variable name='WW_isScanned' value=[TRUE] 
I understand, that this variable is added to a ship itself, not an element of an array? So when this particular ship will become part of another array then he will still have this variable TRUE?
“A mind is like a parachute. It doesn't work if it is not open.”

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

Post by Joubarbe » Fri, 8. Apr 16, 16:51

You cannot do that. You have to do it in two times :

Code: Select all

$myShip = $ship.array[$i]
$myShip -> set local variable name='WW_isScanned' value=[TRUE]
But it's better to use the for each X-Studio macro :

Code: Select all

for each $ship in array $ship.array
  $ship -> set local variable name='WW_isScanned' value=[TRUE]
end

Irrehaare
Posts: 66
Joined: Sun, 15. Nov 15, 19:20
x3ap

Post by Irrehaare » Fri, 8. Apr 16, 18:11

Thanks for all that help! :) But let me ask:

Where can I read about all of this, so I don't have to spam my endless questions here?
“A mind is like a parachute. It doesn't work if it is not open.”

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

Post by X2-Illuminatus » Fri, 8. Apr 16, 18:28

Basic explanations of the Script Editor, and the syntax and logic of its scripting language can be found in the MSCI Handbook, which, while originally written for X2: The Threat, is still relevant to the Script Editor in later games, such as X3TC/AP. Explanations of many commands can be found in the MSCI reference forum. There are also a couple of general information topics. Additionally, you will find many guides and useful bit of information linked in the Tutorial and Ressources Sticky thread. (Similar overview topics can be found in the other Scripts and Modding forums (for X2 and X3R) and may contain useful information too.)
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
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Fri, 8. Apr 16, 20:05

Also, if you don't understand some commands, you can right click on it in X-Studio, then "Find usage in scripts". There are many scripts by default, and a lot of things to learn from them.

But don't hesitate to ask, this is exactly the purpose of this forum :) (yeah, it's not about silly complaints and dull comments, unbelievable isn't it ?)

Irrehaare
Posts: 66
Joined: Sun, 15. Nov 15, 19:20
x3ap

Post by Irrehaare » Sat, 9. Apr 16, 20:09

Ok, so let's ask :D

I wrote something and I am worried that there is some fatal mistake somwhere.

Firstly there is a script that I would like to run on an M5 as a command:

Code: Select all

infinite loop detection enabled=[TRUE]

*freight scanner check
skip if [THIS] -> get volume of ware {Freight Scanner} in cargo bay
   return null

*targets parameters
$flags = [Find.Multiple] | [Find.Enemy] | [Find.Nearest]
$class = [Huge Ship] or [M7]

LFT:
$ship.array = find ship: sector=[Sector] class or type=$class race=null flags=$flags refobj=[THIS] maxdist=99999 maxnum=null refpos=null
$ship.num = size of array $ship.array
$i = 0
while $i < $ship.num
   $ship = $ship.array[$i]
   if not $ship -> get local variable: name='WW_isScanned'
       = [THIS]-> call script '!move.scan.ship' : ship=$ship
       goto label LFT:
   end
   inc $i
   = wait randomly from 20 to 50 ms
end

return null
...and the script it called:

Code: Select all

infinite loop detection enabled=[TRUE]
$fscan.range = get freight scanner range
$prec = $fscan.range - 500
*PROBLEM1
[THIS]-> set destination to $ship

* Move to target
$ship.sec = $ship-> get sector
while not [SECTOR] == $ship.sec
   = wait randomly from 100 to 150 ms
   = [THIS]-> call script '!move.movetosector' : targetsector=$ship.sec
end

* move to ship
$ship.dist = get distance between [THIS] and $ship
while $ship.dist > $prec
   = wait randomly from 100 to 150 ms
   *PROBLEM2
   = [THIS]-> follow object $ship with precision $prec m    
   if [THIS] -> is in freight scanning range: ship=$ship
      *PROBLEM3
      $result = [THIS] -> scan potential pirate $ship for illegal wares
      $ship -> set local variable: name='WW_isScanned' value=[TRUE]
      break
   end
   $ship.dist = get distance between [THIS] and $ship
end

return null
I see three problems or things that worry me:
PROBLEM1: I must have done sth wrong in calling the scriot, as compiler says: "The variable '$ship' on line 12 is being used without being assigned
PROBLEM2: I'm not so sure about follow comand; Will the script stop until it reaches one of its endings, like [FLRET_TARGETREACHED]? I am assuming use of quick M5 for now, I know it will fail if THIS is slower than target
PROBLEM3: Isn't there some normal way to scan only? I don't care about illegal wares, I just want to know what turrets is the ship mounting :P

There are still some things to be added, like order what to do after scanning all or check for police license or ability to specify targets by player, but I want to focus on main problem first.
“A mind is like a parachute. It doesn't work if it is not open.”

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

Post by Joubarbe » Sun, 10. Apr 16, 21:26

1/ Yeah, $ship is not assigned as a "variable", but as an argument of your script. X-Studio doesn't really know that. Ignore that.

2/ I'm not sure either ; if I were you I would call a script that manage entirely the scanning process the way you want it to be managed. Remember that :

Code: Select all

= $ship -> call script 'scanShit' :
will have to be terminated before the code can move along to the next lines. However :

Code: Select all

START $ship -> call script 'scanShit':
will start a script on task 0 of the target ($ship here), independently from the script that calls it.

3/ the 'scan potential pirate' command will make the ship scanned, exactly like if you hit the "scan" button yourself. A lot of commands have stupid names :)

(4/ Your "goto label LFT:" in your first script looks strange.)

Irrehaare
Posts: 66
Joined: Sun, 15. Nov 15, 19:20
x3ap

Post by Irrehaare » Mon, 11. Apr 16, 01:51

Joubarbe wrote:2/ I'm not sure either ; if I were you I would call a script that manage entirely the scanning process the way you want it to be managed.
I'm doing it, i think: first script decides what to scan and second is going to target and scanning it. I hope :P
Joubarbe wrote:(4/ Your "goto label LFT:" in your first script looks strange.)
I've made it to by a loop, I know it's not elegant to do it by goto, but it seemed to fit. The trick is that after scaning sth ship will make now array and again find closest unscanned target and go to it. And the only way for a script to definitely end is to find nothing unscanned.

Also in second script:
If I had while with some infinite condition will it end only after the target is scanned, since scanning and break are in the same IF?

And if I have script X calling normal way for Y, and Y calls for Z with start, will object go back to X after completing Z? I'm guessing it won't?
“A mind is like a parachute. It doesn't work if it is not open.”

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

Post by Joubarbe » Mon, 11. Apr 16, 10:31

FYI, you can also do that:

Code: Select all

LFT:
$ship.array = find ship: sector=[Sector] class or type=$class race=null flags=$flags refobj=null maxdist=null maxnum=999 refpos=null
$ship.array = reverse array $ship.array

for each $ship in array $ship.array
  if not $ship -> get local variable: name='WW_isScanned'
    = [THIS] -> call script '!move.scan.ship': ship=$ship
    goto label LFT:
  end
end
And make your own script nomenclature : 'WW.move.scan.ship', something like that. Scripts with the '!' prefix are vanilla ones.

For your other questions, you probably want to take a look at the sections 7.1 and 7.2 of the MSCI Handbook, and at the 'interrupt task' command.

Example from ADS:

Code: Select all

if $grid.select-> is task 0 in use
  $grid.select-> interrupt with script 'anarkis.ads.cmd.protectgrid' and priority 10: arg1=$enemy arg2=$sector arg3=null arg4=null
else
  START $grid.select-> call script 'anarkis.ads.cmd.protectgrid' : attacker=$enemy tg.sector=$sector
end
One advice with MSCI: always test things. Some stuff don't work as they should :)

Also, the script '!move.scanpatrol' seems to have plenty of answers for you :

Code: Select all

...
if $state == 0
  $ret = [THIS]-> follow object $target with precision 3000 m
  if $ret == [FLRET_TARGETREACHED]
    $state = 1
  end
else if $state == 1
  * first message, we are scanned
...

Irrehaare
Posts: 66
Joined: Sun, 15. Nov 15, 19:20
x3ap

Post by Irrehaare » Mon, 11. Apr 16, 10:46

Thanks a lot. I did read msci handbook chapters that you mentioned, but I'm not sure if I understood them right. It's good to know it's not always right.

I'll be back after first tests (either with questions or hopefully, alpha version :D )
“A mind is like a parachute. It doesn't work if it is not open.”

Irrehaare
Posts: 66
Joined: Sun, 15. Nov 15, 19:20
x3ap

Post by Irrehaare » Tue, 12. Apr 16, 06:36

And I didn't handle adding script as a command ;/

Language file was created in X-Studio and is named '7500-L044.xml'. It look like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Generated using X-Studio -->
<language id="44">

	<page id="2008" title="scipt objects commands" desc="" voice="no">
		<t id="550">COMMAND_TYPE_FIGHT_50</t>
	</page>

	<page id="2010" title="commands" desc="" voice="no">
		<t id="550">Scan all Capital</t>
	</page>

	<page id="2011" title="commands" desc="" voice="no">
		<t id="550">SCN.ALL.CAP</t>
	</page>

	<page id="2022" title="command info" desc="" voice="no">
		<t id="550">This command orders a ship to scan all M7, M2 and M1 ships in sector he`s in. Ship must have a freight scanner. It`s highly advised to use M5. This is ALPHA version of Scan All Capital by Irrehaare.</t>
	</page>
</language>
Setup file is named 'setup.WW.scan.all.cap.xml'. Here's the code:

Code: Select all

load text: id=7500

set script command upgrade: command=[COMMAND_TYPE_FIGHT_50 (350)]  upgrade={Fight Command Software MK1}
set ship command preload script: command=[COMMAND_TYPE_FIGHT_50 (350)] script='WW.scan.all.capital.xml'
global script map: set: key=[COMMAND_TYPE_FIGHT_50 (350)], class=[Moveable Ship], race=[Player], script='WW.scan.all.capital.xml', prio=0

return null
What is NOT a problem:
-ships have fight command software mk1
-scripts in setup are correct

What IS a problem:
-there is no now command in any of ship menus
-I give my command costum name as script object (like COMMAND_SCAN_ALL_CAP), becouse setup script couldn't compile
-after launching a game galaxy map had a problem, lines beetwen sectors disappeard:
http://imagizer.imageshack.us/v2/1024x7 ... xAXkdF.jpg


{Images posted directly to the forums should not be greater than 640x480 or 100kb, oversize image now linked - Terre}
“A mind is like a parachute. It doesn't work if it is not open.”

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

Post by Joubarbe » Tue, 12. Apr 16, 12:02

Commands are not my cup of tea ; I can only advise you to take a deeper look into other scripts to see how they are implemented.

The t file (7500-L044) seems ok though. However, in your scripts, when you call another script, I'm pretty sure the ".xml" must be removed.

"class=[Moveable Ship]" -> maybe you should put the proper classes you need here.

But again, not my cup of tea ; I try to avoid implementing new commands, there's enough of them in the vanilla game :)

Post Reply

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