How to get AI ships to protect their sector

The place to discuss scripting and game modifications for X²: The Threat.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

User avatar
Reven
Posts: 1133
Joined: Thu, 10. Jul 03, 07:42
x4

How to get AI ships to protect their sector

Post by Reven »

You may have noticed that the Argon Collosus that resides in Ore Belt is something of a white elephant (not to be confused with a Split Elephant, which is similar, but a white elephant is more useful). The captain seems to be having a perpetual bath, since pirates and Khaak can thumb their noses at the ship without it doing anything.

Fear not. This is an excellent opportunity to learn a very little bit about scripting. We can jumpstart the ship, drain the captain's bath water, and force them both to work for a living.

The first thing to do, if you haven't already, is to enable scripting. With scripting enabled, you'll feel like you have wings (forgive the pun). The topic on how to enable scripting is covered quite well elsewhere, so we will skip to the interesting information.


Requirements
There are two very simple scripts that you will need to obtain before starting: Download both the above scripts and place them in your x2\scripts folder. The next time you run the game and go into the script editor, they should be visible.

[Note: you may need to right click on the links and save them through the popup menu - in Mozilla select "Save link target as" - don't remember what it is in Internet Exploder]

The Procedure
  1. Make sure you are not in the sector where the target ship is located. This is important. If you don't have any assets in the sector, then go in and drop a sattelite so that you can see the target when you are out of the sector. Then, get out.
  2. Now, we need to take away the ship's license to loaf around. That is, we need to terminate the script that is telling it to idle. Select the ship and get it's "I"nfo. As you page down you will see the scripts that it is running. You are looking for the script called "ship.cmd.idle.std". When you see that script, find it's PID (process ID) as shown in the picture and write it down.

    [ external image ]
    What a PID looks like.
  3. Bring up the command console ("SHIFT + C") and select scripts ("S") and enter the script editor. Locate the "KillProcess" script, highlight it and run it ("R"). You will need to tell the script what ship it is to run on. Select the sector with the target ship, then select the target ship. Then you will need to enter the PID number, so select <number> and then type in the PID you obtained for the idle process. That's it. Check on the target ship and you should see that the idle command is no longer running.
  4. Now you need to enter the sector the target ship is in. When the game loads up the sector, part of the initialization will tell all the turrets on the target ship to attack enemies. You can see this if you go into the ship's info again. You should see a "turret.killenemies.std" process for each turret the target ship has. We're almost there.
  5. Now we do the real work - we tell the ship to attack all the enemies in the sector. This is done by forcing the ship to run the "ship.cmd.killenemies.std" command. The "ForceProtectSector" script that you downloaded will do just this. Bring up the script editor and run that script. You will need to select the target ship twice. The first time tells the script which ship it is to run on. The second time tells the script what its target is (in this case itself).
  6. If you have done this right, in the target ship's info screen, you should see these scripts running:

    [ external image ]
    Correctly run protect script.
Congratulations! You have kickstarted the ship into doing its job.

One thing to note, is that this procedure will tell the ship to attack all enemies no matter where in the sector that they are. If there is a pirate base in the sector way off the map, then any time a pirate launches from the base, the ship will go off to attack it. If you don't want this to happen, then instead of the "ForceProtectSector" script, you can download and use the "ForceProtectLocation" script instead. This script tells a target ship to attack all enemies within a certain radius of a position. When you run it, it will ask you for the target ship (twice as before), a sector location (select this by selecting the sector and then the position within the sector with the crosshairs), and a radius. The ship will attack any enemies within that radius from the location you specify. Remember, the radius is not in kilometers, it is in meters. So mulitply the kilometers by 1000. A good number I use is 40000.
You were warned... pirates will be hunted down like vermin.

Ex Turbo Modestum
User avatar
Reven
Posts: 1133
Joined: Thu, 10. Jul 03, 07:42
x4

Post by Reven »

I know this post is a little basic for most folks here. It's designed as a beginner's tutorial for the player's guide to help someone who's never run a script before.
You were warned... pirates will be hunted down like vermin.

Ex Turbo Modestum
ShadowTek
Posts: 480
Joined: Sat, 20. Dec 03, 19:05
x2

Post by ShadowTek »

Cool, great post, thanks for the info
Proud member of the PHPBB Network!
Feel free to upload or download X2 Mods!!
UncaPathy
Posts: 74
Joined: Mon, 22. Dec 03, 02:29
x3

Post by UncaPathy »

Thanks! I never have done scripting. That darn Collosal elephant really bugs me :wink:

Now to just get the script editor to come up :oops: :roll:


Hmmm...I do NOT see ANY script running. Using a Regular Nav sat to see sector.
Last edited by UncaPathy on Thu, 22. Jan 04, 04:44, edited 1 time in total.
User avatar
Rakeris
Posts: 407
Joined: Wed, 31. Dec 03, 04:25
x4

Post by Rakeris »

Type in Thereshallbewings any where in the game with a capital T
UncaPathy
Posts: 74
Joined: Mon, 22. Dec 03, 02:29
x3

Post by UncaPathy »

Dragonslayer: Finally saw the menu choice :oops:
User avatar
Storm_Front
Posts: 1021
Joined: Mon, 15. Dec 03, 05:27
x2

Post by Storm_Front »

Reven wrote:I know this post is a little basic for most folks here. It's designed as a beginner's tutorial for the player's guide to help someone who's never run a script before.
Basic is good.
UncaPathy
Posts: 74
Joined: Mon, 22. Dec 03, 02:29
x3

Post by UncaPathy »

I agree, basic is good! :D

It works!

That elefant finally is doing its job :P :roll:
khass
Posts: 27
Joined: Thu, 15. Jan 04, 03:23
x3

Post by khass »

Do you have to do this everytime you start the game?
User avatar
Reven
Posts: 1133
Joined: Thu, 10. Jul 03, 07:42
x4

Post by Reven »

khass wrote:Do you have to do this everytime you start the game?
Good question. I should have noted this in the tutorial. No, once you do this, it is permanent. Or, until you use "KillProcess" to terminate it. It will be saved in your save-games.
You were warned... pirates will be hunted down like vermin.

Ex Turbo Modestum
caong28
Posts: 5
Joined: Thu, 11. Dec 03, 01:17
x2

Thanks!

Post by caong28 »

You da man Reven!

I'll give it a try when I'm in the game next time... busy finishing off my thesis at the moment.

Any ideas on how to make a ship patrol? For example, I have a Split Dragon in Ore Belt, and I want it to routinely fly a circuit through, say, Cloudbase southeast, Power Circle, President's End and Cloudbase southwest. And attacking all enemies it comes across before resuming the patrol circuit.

Thanks!
User avatar
Reven
Posts: 1133
Joined: Thu, 10. Jul 03, 07:42
x4

Post by Reven »

The built-in combat scripts seem to have provisions for patrolling, so yes, it should be relatively simple. Just needs an interface into it somewhere. I'll work on it tonight.
You were warned... pirates will be hunted down like vermin.

Ex Turbo Modestum
Steel Chicken2
Posts: 97
Joined: Mon, 19. Jan 04, 21:33

Post by Steel Chicken2 »

Im using V 1.1, and I dont see the scripts on the colossus, I have it enabled ive used scripts on my ship, but when im out of the sector, and select the colossus, it says script tasks info:
and then blank lines....what am I missing?

[/img]
janonol
Posts: 194
Joined: Fri, 26. Sep 03, 06:32
x3

Post by janonol »

This is good.

BAsic helps

cool :D
User avatar
Reven
Posts: 1133
Joined: Thu, 10. Jul 03, 07:42
x4

Post by Reven »

Steel Chicken2 wrote:Im using V 1.1, and I dont see the scripts on the colossus, I have it enabled ive used scripts on my ship, but when im out of the sector, and select the colossus, it says script tasks info:
and then blank lines....what am I missing?
You may need to use PAGE DOWN to scroll down to see it.
You were warned... pirates will be hunted down like vermin.

Ex Turbo Modestum
tr
Posts: 45
Joined: Wed, 17. Dec 03, 17:31
x4

Post by tr »

@ Reven regarding ForceProtectLocation script:

is it really necesarry to select ship twice?
cannot be THIS used instead (maybe with a check if not null) ?


thanks for your info, happy this pot is moving again ...
Shatshoveler
Posts: 12
Joined: Sat, 17. Jan 04, 19:08
x2

Post by Shatshoveler »

Hi, at first this protect sector script worked like a charm, but now the colossus has completely dissappeared and there are 8+ pirates harassing my station. Its not really a problem right now since their weapons are so weak and they are ignoring my transports, but the "warning, station is under attack" message is driving me crazy
coxpwr
Posts: 124
Joined: Mon, 28. Apr 03, 08:10
x2

Post by coxpwr »

* KillProcess - kill a running process by its Process ID (PID)
* ForceProtectSector - Force a ship to engage all enemies in a sector [/quote]

Link to these seems broken , you got another place that I can find these?
Steel Chicken2
Posts: 97
Joined: Mon, 19. Jan 04, 21:33

Post by Steel Chicken2 »

Well the process ID info is still not there, but I ran the script anyways and it seems to work ok...
User avatar
Reven
Posts: 1133
Joined: Thu, 10. Jul 03, 07:42
x4

Post by Reven »

tr wrote:@ Reven regarding ForceProtectLocation script:

is it really necesarry to select ship twice?
cannot be THIS used instead (maybe with a check if not null) ?

thanks for your info, happy this pot is moving again ...
Yes, I could have done that. I got some strange results when I first did this, though - I would have to run the script twice before it would "take hold". I'm doing more digging into the way things work, and will update the scripts when I know more.
You were warned... pirates will be hunted down like vermin.

Ex Turbo Modestum

Return to “X²: The Threat - Scripts and Modding”