Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How to make multi shot weapon, rapid fire weapon?  (Read 1437 times)

DWARFFRAWD

  • Bay Watcher
    • View Profile
How to make multi shot weapon, rapid fire weapon?
« on: August 28, 2018, 09:40:14 am »

Like blunderbuss, auto musket in 44.12 musket mod,

How to change number of projectiles and fire rate?

Is it need some code? Dfhack?
Logged

SpeardwarfErith

  • Bay Watcher
    • View Profile
Re: How to make multi shot weapon, rapid fire weapon?
« Reply #1 on: August 28, 2018, 10:27:44 am »

Yes, you need to do some coding and dfhack.

The variable that controls the fire rate is <a dwarf>.counters.think_counter
When a dwarf shoots a weapon, think_counter on the dwarf that shot it is set to a value between 100 and 40, depending on the dwarf's skill. It goes down by 1 every tick and when it reaches 0 the dwarf can shoot again.

To make the dwarf shoot faster, you need to check if think_counter is set to a high value, and if it is make it smaller. The smaller the value the faster the dwarf will shoot.

I don't know how the auto musket's code looks, but a script I wrote that does the same thing looks like this:

Code: [Select]
local eventful = require 'plugins.eventful'

print("rapidfire enabled")

eventful.onProjItemCheckMovement.rapidfire = function(projectile)
if projectile.distance_flown == 1 then
adjustFireRate(projectile)
end
end

function adjustFireRate(projectile)
local fireRate = nil
if projectile.firer == nil then --if the projectile wasn't shot by somebody, like a flying corpse
return
end
if projectile.item.subtype.id == "ITEM_AMMO_BULLET_LIGHT" then
fireRate = 20
elseif projectile.item.subtype.id == "ITEM_AMMO_BULLET_HEAVY" then
fireRate = 100
end
if fireRate ~= nil and projectile.firer.counters.think_counter > fireRate then
projectile.firer.counters.think_counter = fireRate
end
end

This code will make any gun that shoots a custom ammo called "ITEM_AMMO_BULLET_LIGHT" shoot very fast, and any gun that shoots "ITEM_AMMO_BULLET_HEAVY" shoot very slow.
Logged
The swordsman Smoma Acaltekud: Hello Ago. Life is, in a word, death.
The swordsman Smoma Acaltekud stabs you in the lower body with his iron scimitar, tearing apart the muscle and tearing apart the left kidney!
The iron scimitar has lodged firmly in the wound!

Battle Royale Mode: A DFHack Script