As the overly long title indicates, this here is a separate topic for the scripts I cobbled together from bits of zaporozhets' work among others for my historic weapons mod.
Right now I've got a script that looks for projectiles, compared the ammo, weapon or material type against a table with properties and assigns said properties. The second script checks for reactions and building items, using mainly reaction reagents to stick ammunition in the 'barrel' building item and a fire command to spit them out at stuff.
The first script got a bit.. out of hand in terms of features I actually needed for a historic weapons mod, but making a minigun was just too much fun to not do. I've made it so it only checks once what properties and function it uses so it should only burns resources for functions you actually assign to any particular item/material. What testing I've done with spamming a couple hundred projectiles / 100 ticks shows fairly minimal performance impact, at least until you make each of those projectiles spawn a ton of flow effects each tile.
modtools/projectile-mod
===========================
Creates smoke and modifies various properties of any projectile, based on ammunition, weapon or material.
-clear
unregister all entries
-list
list current ammo/weapons/material entries and their values
-ammoType, -weaponType or -materialType
register projectile, weapon or material with subtype (eg ITEM_AMMO_BOLTS) or full material token (INORGANIC:IRON or CREATURE_MAT:DWARF:LIVER). Applies to ANY projectile subtype or material, and anything used as a ranged weapon (including non-weapon item set as bow_id).
if ammo, weapons or materials have the same value defined, they will either be added, multiplied or overwritten with the following precedence: ammo > weapon > material
valid arguments:
-deviation - max number of tiles at 50 tiles distance. Additive, decreases with weapon/ammo item quality if qualityScale is > 0.
-range - minimum range, maximum range. projectile will not hit targets until minimum range is reached, and drop from the air triggering any impact effects at max range. defined as [ min max ] or just max (no brackets) to keep default minrange behaviour.
-falloff - projectile velocity is multiplied by this every 4 tiles of distance flown. 1 is constant speed (default behavior), below 1 has speed drop over distance, above 1 accelerates the projectile.
gravitates towards 1 depending on ammo item quality and qualityscale. Falloff stops happening at qualityScale 2 and masterwork quality. Strange things start happening beyond that number.
-hitrateAdd - 0(default) to 100, adds or substracts hitrate. increases with firer skill. Stacks additively, increases with weapon/ammo item quality if qualityScale is > 0.
-velocity - multiplies the projectile velocity, can exceed weapons max velocity. Stacks multiplicatively, increases with weapon/ammo item quality if qualityScale is > 0.
-qualityScale - multiplier, scales accuracy, hitrate and velocity with item quality. 0 for no scaling, 1 for default scaling. Accepts fractions and values higher than 1. Additive, does nothing on materials.
-breakChance - 0 to 1(default), chance for the projectile to break. Multiplicative.
-piercing - true/false, sets true if no argument. whether or not a projectile will pass through targets to hit another. causes projectiles to hit one target multiple times, may be a bug. Overrides by precedence.
-deleteMe - true/false, sets true if no argument. if set with no argument, deletes projectile on impact. if set with a number, deletes it at that range without triggering impact effects. Overrides by precedence.
-setType - TYPE:SUBTYPE, transform projectile(s) into this item. Changing item type not currently supported. Overrides by precedence.
-setMat - change the projectile's material. Overrides by precedence.
-shotCount - spawn extra projectiles if > 1, no theoretical limit the number. Multiplicative, rounds downwards.
-shotRof - if set, each extra shot is fired with this many ticks delay. if not set, all shots fire at once. Overrides by precedence.
-rofMult - multiplies baseRof and altRof, multiply rate of fire. Multiplicative.
-weaponType only values
-baseRof - delay in ticks between shots and firer skill scaling defaults are 80 and 1, skill scaling can be a fraction and more than 1.
-altRof - delay in ticks, interval and firer skill scaling. each shot in the number for interval will take this long instead. defaults for interval skill scaling are 2 and 1 respectively.
-windupRof - multiplier, shot-until-woundup, ticks per winddown. multiplies fire delay. delay gravitates towards 1 each shot until the second value is reached, and steps back by 1 shot each delay.
-trailFlow or -impactFlow
add flow effects to projectiles during flight or at impact. arguments is [ ammo/weapon/material subtype/materialtoken ] or just subtype, which will default to ammo trigger.
multiple of each can be added with seperate commands, define flows AFTER the above properties, as they will override the entry for the same ammo/weapon/material.
valid arguments:
-minmaxint - minimum range, maximum range and interval. flow triggers within range, at the specified interval of tiles flown.
minimum and interval default to 1, so a range of 1-20 can be set as [ 1 20 1 ], [ 1 20 ], or just 20.
-flowType TODO
-flowMat - set flow material if the flow type permits it.
-volume - pretty self-explanatory.
-conical - multiply volume by distance flown and this multiplier.
-expand - if set, the flow will expand drift out to more than 1 tile.
-direction - works on fire and dragonfire (type 6 and 7) only, sets direction for the flow to the direction of the projectile.
examples:
make arrows less accurate, have a 50% break chance and lose 6% speed each 4 tiles. also fires 20% faster.
-ammoType ITEM_AMMO_ARROWS -deviation 2 -breakChance 0.5 -falloff 0.94 -rofMult 1.2
a slower, more accurate crossbow. firer skill only increase fire rate by half as much as normal. make steel hit harder and more durable.
-weaponType ITEM_WEAPON_CROSSBOW_ARBALEST \-deviation -1 -hitrateAdd 6 -velocity 1.2 -baseRof [ 145 0.5 ] -breakChance 1.33
-materialType INORGANIC:STEEL -breakChance 0.64 -velocity 1.2 -deviation \-1
make shot of 8 pellets that are deleted after impact and produce smoke for 3 tiles that expands and increases in volume over distance
-ammoType ITEM_AMMO_GUN_20MM_SHOT -deviation 5 -hitrateAdd 5 -velocity 0.6 -deleteMe -subtype AMMO:ITEM_AMMO_GUN_SHOT -shotCount 8
-trailFlow ITEM_AMMO_GUN_20MM_SHOT -minmaxint 3 -flowType 5 -volume 6 -expand -conical 1
a rocket that starts slow but flies faster and faster, hits a single target multiple times (faking explosive effect), turns into a different mat, produces smoke each 2 tiles and a dragonfire explosion. quality only matters half as much in deviation/velocity/hirate as normal. it explodes after traveling 20 tiles.
-ammoType ITEM_AMMO_ROCKET -velocity 0.5 -falloff 1.2 -piercing 1 -deleteMe -range 20 -setMat INORGANIC:EXPLOSIVE_MAT -qualityScale 0.5
-trailFlow [ ammo ITEM_AMMO_ROCKET ] -minmaxint [ 0 20 2 ] -flowType 5 -volume 20 -expand
-impactFlow [ ammo ITEM_AMMO_ROCKET ] -flowType 6 -volume 30 -expand
make a minigun, because why not. each shot produces 3 projectiles at a 5 tick delay, has a 5 tick delay itself and every shot in 20 (so 60 projectiles) has a 500 tick delay. Only the last delay is decreased with firer skill. delays are multiplied by 6, multiplier decreases to 1 at the 8th shot, and winds back down by 1 each 40 ticks. add a material for incendiery ammo for good measure.
-weaponType ITEM_WEAPON_MINIGUN -deviation 5 -hitrateAdd 10 -qualityScale 1.4 -baseRof [ 5 0 ] -altRof [ 500 20 ] -windupRof [ 6 8 40 ]
-ammoType ITEM_AMMO_MINIGUN_AMMO -deleteMe -falloff 0.85 -shotCount 3 -shotRof [ 5 0 ]
-materialType INORGANIC:AP-I -velocity 0.67 -piercing
-impactFlow material INORGANIC:AP-I -flowType 6 -volume 10
https://pastebin.com/VZ0M5F6TThe artillery script I had to make with a thing that checks the job list for matching job names every 50 ticks as long as artillery jobs exist, I tried various solutions checking the job itself rather than the job list but touching dead jobs in any way seems to make the game explode every now and then. The current method works and can modify jobs in between the point of initiating them and completing them, which lets me do cool stuff like having a single job reload every barrel in an organ gun one by one as long as its set to repeat. Similarly, the 'firing' job is basically kept in limbo by extending the job completion timer until a target is found, or if set to repeat until it is out of ammunition.
modtools/arty-mod
===========================
Turns buildings into artillery pieces.
-clear
unregister all entries
-list
list current ammo/weapons/material entries and their values
-artyType
argument is barrel item subtype, such as ITEM_TOOL_BARREL_BOMBARD. will pass properties to any building containing this item, and set the item to be loaded with ammunition. type of ammunition used and the buildings themselves are defined in raws; reactions prefixed with ARTILLERY_LOAD will load their reagents into an empty barrel, ARTILLERY_FIRE will fire the gun and ARTILLERY_ROTATE_R and ARTILLERY_ROTATE_L will rotate the building, if the names of its 4 directions end in _N, _E, _S and _W. 1x1 guns will fire in all directions and do not need rotate reactions. multiple barrels can be housed in a single building, setting the load and fire jobs to repeat will load/fire until all barrels are loaded/unloaded.
-shootForce - amount of force the projectile is give, works exactly the same as ranged weapon raw shoot force token (shoot force * 50000 / size * density)
-range - minrange, maxrange. affects targeting and projectile behavior, targetting is done within range, actual projectile maxrange is maxrange + 3 to prevent guns wasting ammunition on targets moving around the edge of targeting range.
-loadTime - delay, skill scaling. time in ticks it takes to load a barrel and how strongly this scales with skill. defined as [ number scale ] or just number, in which case scaling defaults to 1.
-rotateTime - delay, skill scaling. same as loadTime, only for building rotation.
-baseRof - delay, skill scaling. delay between shots for multibarrel buildings, if fire is set to repeat.
-altRof - delay, interval, skill scaling. every (interval) many shots this delay is used instead.
-windupRof - delay multiplier, shots before wound up, ticks per winddown. multiplies delay until a certain number of shots is fired, and winds back down once the gun stops firing.
examples:
-artyType ITEM_TOOL_BARREL_BOMBARD -loadTime 1000 -range 100 -shootForce 72000 -rotateTime 600
-artyType ITEM_TOOL_BARREL_HANDGONNE -loadTime 180 -baseRof 30 -range 40 -shootForce 4000 -rotateTime 200
https://pastebin.com/bq9kutS9I do plan to extend both of these somewhat. Particularly ranged-mod is pretty easy to add function to at this point, I plan to expand it to the point where I can a cool DOOM guns mod. I already got a minigun (windup and reduced ammo consumption and all) working, so shouldn't be tremendously long until then.
Hope its of some interest to someone, and of course anyone is free to use/modify/improve/make worse these! A lot of credit goes to zaporozhets, give his stuff a look:
http://www.bay12forums.com/smf/index.php?topic=171742.0