[Script] Point Defence. An advance turret defence script

The place to discuss scripting and game modifications for X³: Reunion.

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

Jasper Carrot
Posts: 168
Joined: Mon, 15. Dec 03, 01:04
x3tc

Post by Jasper Carrot »

Oh well, just askin, never know till you try right?

I downloaded your script anyway to give it a go :)
User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent »

Erhm.. I didn't actually upload the script you wanted me to make, I just deleted it as it worked almost indifferently to just the stock x3 scripts
ShadowDragon8685
Posts: 185
Joined: Mon, 7. Aug 06, 21:40
x4

Post by ShadowDragon8685 »

Just as a question, I wonder if a further-advanced script might be possible without being too resource intensive.

Basically, I would like to be able to assign target priorities as follows:

1: Missiles! Gor, I hate missiles!
2: Drones
3: Enemy Fighter that is FIRING ON ME!
4: Enemy ships that have lost shields (10% or less shielding)
5: Closest enemy fighter


This means that, if a missile is fired at me, all turrets which have it in their line of fire drop whatever else they're doing and shoot it down. After missiles, they prioritize enemy drones, since the can basically sweep the skies of them easily.

After missiles and drones are no longer incoming, the turrets will turn their attention to any M3/M4/M5 in their fire arc that is shooting at me, and if they can't find one of those, they'll take targets of opportunity - basically, if they can get some hits in on an enemy whose pants are down, where they have a chance to get in some hull damage they'll take it. And after that, if no such targets present themselves, all the turrets will focus on the closest enemy fire, not firing at it if they don't have an angle.
User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent »

Currently, it prioritises (iff they are in its firing arc)

1: Missiles aimed at me
2: Nearest Hostile small ship (which incompeses tp's ts's m3-m5's, and fighter drones are m5's)


Whilst it is possible to do the prioritisation you suggested, I wouldn't recommend it, as if you look at the script

Before it was something like:

Code: Select all

Victim = Find nearest missile aiming at me
if Victim doesn't exist
   Find nearest enemy in range of my turret
end
Where it would find the nearest missile, on failing that, the nearest hostile.


In order to make it have small ship prioritisation (And to to it efficiently), as well as track multiple missiles, I had to expand the code... considerably...

Code: Select all

024   * Phase 1, Targeting
025   * Scan for missiles
026     $missile = [THIS] -> find nearest missile aiming to me
027     if $missile -> exists
028      if [THIS] -> is $missile in firing range of turret $turretid
029       $victim = $missile
030       goto label targetlocked
031       
032      else
033       $victimarray = [THIS] -> get array of missiles aiming to me
034       $size =  size of array $victimarray
035       if $size > 1
036        skip if $size < $maxtargets
037         $size = $maxtargets
038        
039        $count = 0
040        while $count < $size
041         $missile = $victimarray[$count]
042         if [THIS] -> is $missile in firing range of turret $turretid
043          $victim = $missile
044          goto label targetlocked
045         end
046         inc $count = 
047        end
048       end
049       
050      end
051     end
052     
053     
054     
055   * Scan for small targets
056     $victim =  find ship: sector=$sec class or type=Little Ship race=null flags=$flags1 refobj=[THIS] maxdist=$distance maxnum=null refpos=null
057     
058     if not [THIS] -> is $victim in firing range of turret $turretid
059      $victimarray =  find ship: sector=$sec class or type=Little Ship race=null flags=$flags2 refobj=[THIS] maxdist=$distance maxnum=$maxtargets refpos=null
060      $size =  size of array $victimarray
061      
062      $count = 1
063      while $count < $size
064       $victim = $victimarray[$count]
065       skip if not [THIS] -> is $victim in firing range of turret $turretid
066        break
067       inc $count = 
068       $victim = null
069      end
070      
071     end

Lines 58 through 69 will have to be repeated for each prioritisation. (Lines 55 is an attempt to make the script more efficient, as anywhere from 1-3 turrets will have the closest enemy in firing range)

On the scripting side it'll add about 10-15 lines per prioritisation, and on the computing side, it'll run the script multiple times on the same ship.
i.e.
First time it'll just do missiles
Then it'll just do drones
Then it'll do all small ships, finding one firing on me (repeating drones again)
Then all do all small ships again, looking for lack of shielding
And on failing all of that just find the nearest fighter

Whilst it would be possible to cut down the computing by creating the array of drones, then an array of ships and running the firing on me/has shields check at the same time, it would still be highly inefficient and very long.

Also I'm not to sure if its possible to see if a ships firing on you at the moment, It is possible to see if your its target thou, but given the nature of the script you will almost always be the target
User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent »

Bump, Script updated, it still does the same thing, just more efficiently now
User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent »

Re updated again, if you downloaded this script in the last week (14th of Feb 08 - 21st) I strongly suggest you download it again. I accidentally set the command's name to the actual missile defence (Something left over from the mod I made it from)

New Feature, volleies (which is actually apparently spelt volleys... damn it). Will fire the standard 3 shot bursts, but will fire up to 15 volleys (of 3 shots bursts) per target, before it finds a new one (still performs all other functions normally)
This is to because hit probabilities are maximised when the target is closer to the ship, but when a ship gets hit, it tends to fly evasive and hang around near the edge of the firing range, mean while, there are plenty of fat juicy targets sitting closer to you just asking for a bit of ak ak.
Its set to 15 (which is a fair amount) simply because if you set it to one, it spends more time turning the turret then firing, so I thought 15 is a nice balance of fire-rate versus accuracy.
User avatar
Elffin
Posts: 371
Joined: Wed, 18. May 05, 22:34
x3tc

Post by Elffin »

Will try this out - looks fun...!
Neskiairti
Posts: 36
Joined: Thu, 29. Nov 07, 18:58
x3tc

Post by Neskiairti »

ahh.. awesome sauce! I'll just have to make sure i have a fast weapon on the turret :P not something like a Concussion Impulse gun or some such..
Eeep! it got me again!
Torias
Posts: 167
Joined: Sun, 23. Jan 05, 15:23
x4

Post by Torias »

Very shiny script ^_^ Thanks!

Return to “X³: Reunion - Scripts and Modding”