Author Topic: Weapon hit detection script  (Read 127 times)

0 Members and 1 Guest are viewing this topic.

Offline Goober5000

  • HLP Loremaster
  • Administrator
  • 214
    • Goober5000 Productions
Weapon hit detection script
This script was inspired by one that m!m originally created for Scroll.  I ended up almost entirely rewriting it as our needs expanded beyond the specific use case that m!m wrote it for.  With this script, you can monitor ships and subsystems for any hits by a particular class of weapon.
http://scroll.hard-light.net/downloads/weapon_hit-sct.tbm

There are two main functions to use:

WeaponHit:addHitDef(weapon_class_name, ship_name, subsys_name)
Call this function at the beginning of the mission add the "hit definition" consisting of the weapon class, an optional ship (or nil for all ships), and an optional subsystem (or nil for a hit anywhere on the ship).  The game will update these definitions whenever a weapon hit is detected.

WeaponHit:checkHit(variables, weapon_class_name, ship_name, subsys_name)
Call this function periodically to check for hits.  If any hit is detected, and you supply one or more variables, those variables will be populated with the results.  Possible variables are age, recording the age in seconds since a hit was detected, and x, y, and z, recording the world coordinates of the hit.


Example:

Code: [Select]
$Formula: ( when
   ( true )
   ( script-eval-block
      "WeaponHit:addHitDef('TAG-B', "
      "'Arachnas', 'turret02')"
   )
)
+Name: Initial setup
+Repeat Count: 1
+Interval: 1

Then:

Code: [Select]
$Formula: ( when
   ( and
      ( perform-actions
         ( true )
         ( script-eval-block
            "WeaponHit:checkHit({age='hit-Ar"
            "achnas-turret02-age'}, 'TAG-B',"
            "'Arachnas', 'turret02')"
         )
      )
      ( = @hit-Arachnas-turret02-age[-1] 0 )
   )
   ( send-message
      "#Command"
      "High"
      "Tag successful"
   )
)
+Name: TAG successful
+Repeat Count: 1
+Interval: 1