Very impressed after a cursory reading. As a fellow noob to lua, I did not know you could set table keys like that.
I did notice you set multiProjectile.distance_flown to 6 to avoid smoke, I initially did something similar on the blunderbuss before I noticed it seemed to be teleporting the projectiles forward. It's not a problem really unless the target is nearly adjacent.
Making a general purpose projectile script is a brilliant idea.
Ah... I hadn't noticed, but this sure explains the issue of shot projectiles not hitting stuff. Thanks, I'll have to come up with something else for that. I've also manually carried over the firer ID to the multiProjectile since the one in makeProjectile didn't seem to work; shot projectile hit combat reports weren't showing as coming from the player character in adventurer mods.
I've had this issue too and just sidestepped it by giving the weapon a new ammo, the only way I could think of using the same ammo was iterating through the firers inventory on distance_flown == 0, getting projectile.firer.inventory[indx].item.subtype.id and checking against the weapon name (or checking subtype.subtype, but I like strings for readability), but it was for the automusket and I was worried about the overhead and so didn't go any further with it. Hope that works for you.
Hmm yeah, I considered something like that but I had hoped I could circumvent it by using the bow_id. It does seem to correspond to whatever ranged weapon is being used, but I can't figure how to use it. Anyhow, thefriendlyhacker probably had a point, I'll give your idea a try.
Interesting stuff. I'll need have to have more of a mess around with the projectile flags, I have no idea what I'm doing with them. I just copied them in from Roses projectile script and I keep getting a weird bug on the cannon where it only causes light bruising, setting the piercing flag seemed to fix it but now I'm not so sure it did what I thought given what you've said. Maybe I should just make the cannonball use an edge attack. Has anything like that happened to you?
Some blunt objects seem to have that effect, I've set cannonballs to be edged since they pretty much behave that way judging by historic records. Piercing is appropriate for cannonballs too, since they tended to tear through lines with fairly little regard for how many soldiers were in the way.
Edit: Alright, got weapon properties to work. Seems projectile.bow_id is the item.id of the weapon used to fire the projectile, so that let me avoid the issue of not being able to figure out which weapon was used to do the shooting, avoiding cases like 'Urist is holding a machinepistol and a shotgun, his shotgun is now a machineshotgun'.
There is uh... probably a more graceful way to do this, but I couldn't find how to match item.id directly so here's what I ended up with:
weaponProperties = {
["ITEM_WEAPON_CROSSBOW_ARBALEST"] = { deviation = 0, hitrateMod = 0, velocityMult = 1, rateMult = 0.7 },
["ITEM_WEAPON_CROSSBOW"] = { deviation = 0, hitrateMod = 0, velocityMult = 1, rateMult = 1 }
}
eventful.onProjItemCheckMovement.blam = function(projectile)
if projectile.distance_flown == 0 and projectile.firer ~= nil then
ammoProperty = ammoProperties[dfhack.items.getSubtypeDef(projectile.item:getType(),projectile.item:getSubtype()).id]
if ammoProperty ~= nil then
weaponProperty = { deviation = 0, hitrateMod = 0, velocityMult = 1, rateMult = 1 } -- make sure the script doesn't trip over this being nil
for arg,blargh in pairs(projectile.firer.inventory) do
if projectile.firer.inventory[arg].item.id == projectile.bow_id ~= nil and weaponProperties[projectile.firer.inventory[arg].item.subtype.id] ~= nil then
weaponProperty = weaponProperties[projectile.firer.inventory[arg].item.subtype.id]
end
end
print(weaponProperty.rateMult)
projectileMod(projectile, ammoProperty, weaponProperty)
multiShot(projectile, ammoProperty)
etc...
end
Also I forgot to mention: That laser gun looks pretty cool, and if you should find a way to remove projectiles after they've hit (to prevent a bunch of 'laser beams' laying on the floor) that'd be pretty useful too.