Modding Help Need help with custom abilities for a weapon

Discussion in 'Starbound Modding' started by Detsella Morningdew, Nov 27, 2023.

  1. Detsella Morningdew

    Detsella Morningdew Space Hobo

    So, I have a weapon idea (laser rifle) where the secondary fire is an extreme power beam... that disables the weapon entirely for 120 seconds.

    My idea is to make a custom "weapon recharging" status effect that lasts for that time, but I have two problems. I'm fairly new to modding, so I mostly know how to modify existing things. I have no idea how I'd have a weapon apply status effects to the user, and how I'd add a conditional to both firing modes so that it won't fire at all as long as the status effect is active.

    My second idea if there isn't a convenient way to make a weapon conditionally nonfunctional is to swap the weapon with a non-functional version that has one fire mode - a "recharge core" ability that takes all your energy and swaps the weapon back to the functional version, functionally meaning the special fire mode of the first, real gun would take two full recharges of energy to regain functionality. This would have the added benefit of making me able to have the "depleted" gun have a different fullbright animation to reflect this.

    Not sure how to do that either.
  2. Detsella Morningdew

    Detsella Morningdew Space Hobo

    I think I figured out how to apply a status effect to the user with a projectile that goes backwards and applies the effect, but not how to disable the weapon based on having that status effect.
    Last edited: Nov 27, 2023
  3. Rezetrx

    Rezetrx Void-Bound Voyager

    For that you have to customize the gunfire.lua for your weapon.
    Copy the file from \items\active\weapons\ranged\gunfire.lua into your weapons folder and rename it.

    Inside your weapon (.activeitem) you then change the path to match your custom gunfire.lua
    "primaryAbility" : {
           "scripts" : ["/items/active/weapons/ranged/gunfire.lua"],
    Inside your custom gunfire.lua you then adjust the following:
    function GunFire:init()
        self.overchargeLock = false
    function GunFire:update(dt, fireMode, shiftHeld)
        if self.fireMode == (self.activatingFireMode or self.abilitySlot)
            and not self.weapon.currentAbility
            and self.cooldownTimer == 0
            and not status.resourceLocked("energy")
            and not world.lineTileCollision(mcontroller.position(), self:firePosition())
            and not self.overchargeLock
    function GunFire:CheckOvercharge()
        -- search through all active status effects and serach for your effect
        local cdEffect = util.filter(status.activeUniqueStatusEffectSummary(), function(effect)
            return effect[1] == "Status effect name"
        -- #cdEffect -> number of entries that matched the filter
        if #cdEffect == 0 then
            self.overchargeLock = false
            self.overchargeLock = true

Share This Page