Modding Help Alt Ability and Lua troubleshooting

Discussion in 'Starbound Modding' started by Tuesday's Eyebrow, Sep 23, 2018.

  1. Tuesday's Eyebrow

    Tuesday's Eyebrow Phantasmal Quasar

    I'm trying to make a new alt ability based on the vanilla "charge" alt ability for the spear (It doesn't appear to be used, but when referenced it works just fine, if a bit lackluster)

    To that end, I copied the files located in "/items/active/weapons/melee/abilities/spear/charge/" to my mod folder and changed
    the "type" field under "ability" to "dragoon" and then took my weapon I had made to test abilities and changed it's "altAbilityType" to "chargeedit" as well. Only problem is, when I go into Starbound, the weapon makes the game hang for a half a second when I hold it, sticks straight up and doesn't do anything but look like i'm showing off programmer art. I tried moving it to another folder and changing the fields that reference the files moved to the appropriate addresses but I got zilch.

    What could be causing this and how can I fix it?

    If you need the .weaponability and .lua files, I've "spoiler"ed them below


    {
    "animationParts" : { },
    "animationCustom" : {
    "animatedParts" : {
    "stateTypes" : {
    "dashSwoosh" : {
    "default" : "idle",
    "states" : {
    "idle" : {
    },
    "charge" : {
    "frames" : 4,
    "cycle" : 2.0,
    "properties" : {
    "persistentSound" : "/sfx/objects/teslaspike.ogg"
    }
    },
    "full" : {
    "properties" : {
    "immediateSound" : "/sfx/gun/grenadeblast3.ogg"
    }
    }
    }
    }
    },
    "parts" : {
    "dashSwoosh" : {
    "properties" : {
    "zLevel" : 1,
    "centered" : true,
    "transformationGroups" : ["swoosh"],
    "offset" : [3.75, 0.0625],
    "fullbright" : true,
    "damageArea" : [[-6, 0], [-3.5, 1], [-1.5, 1], [1.5, 0], [-1.5, -1], [-3.5, -1]]
    },
    "partStates" : {
    "dashSwoosh" : {
    "idle" : {
    "properties" : {
    "image" : ""
    }
    },
    "charge" : {
    "properties" : {
    "image" : "/items/active/weapons/drakelance/chargeswoosh.png:<frame>"
    }
    },
    "full" : {
    "properties" : {
    "image" : "/items/active/weapons/drakelance/chargeswoosh.png:4"
    }
    }
    }
    }
    }
    }
    }
    },
    "animationScripts" : [
    "/items/active/effects/lightning.lua"
    ],

    "ability" : {
    "type" : "dragoon",
    "scripts" : ["/items/active/weapons/drakelance/charge.lua"],
    "class" : "Charge",

    "chargeTime" : 2.0,
    "minChargeTime" : 0.5,
    "chargeLevels" : 4,
    // [width, forks, branching, color]
    "lightningChargeLevels" : [
    [1.15, 0, 0.05, [255, 255, 150, 50]],
    [1.15, 0, 0.07, [255, 255, 185, 50]],
    [1.15, 0, 0.09, [255, 255, 215, 50]],
    [1.15, 0, 0.12, [255, 255, 255, 50]]
    ],
    "dashLightning" : [1, 0, 0.12, [255, 255, 255, 50]],

    "dashMaxSpeed" : 200,
    "dashControlForce" : 1600,
    "maxDashTime" : 0.20,
    "maxEnergyUsage" : 50,

    "freezeTime" : 0.1,

    "damageConfig" : {
    "baseDamage" : 6,
    "timeout" : 0.25,
    "timeoutGroup" : "alt"
    },
    "baseDps" : 6, // overrides baseDamage in damageConfig

    "cycleRotationOffsets" : [0, 7.5, -7.5],
    "stances" : {
    "charge" : {
    "armRotation" : -135,
    "weaponRotation" : 45,
    "twoHanded" : true,
    "weaponOffset" : [0.0, 0.0],

    "allowRotate" : true,
    "allowFlip" : true
    },
    "dash" : {
    "armRotation" : -25,
    "weaponRotation" : -65,
    "twoHanded" : true,
    "weaponOffset" : [0.0, 2.0],

    "allowRotate" : false,
    "allowFlip" : false
    }
    }
    }
    }


    require "/scripts/util.lua"
    require "/items/active/weapons/weapon.lua"

    Charge = WeaponAbility:new()

    function Charge:init()
    self:reset()
    end

    function Charge:update(dt, fireMode, shiftHeld)
    WeaponAbility.update(self, dt, fireMode, shiftHeld)

    if self.weapon.currentAbility == nil and self.fireMode == "alt" and not status.resourceLocked("energy") then
    self:setState(self.charge)
    end
    end

    function Charge:charge()
    self.weapon:setStance(self.stances.charge)
    self.weapon:updateAim()

    animator.setAnimationState("dashSwoosh", "charge")

    local chargeTimer = 0
    local chargeLevel = 0
    while self.fireMode == "alt" and (chargeLevel == self.chargeLevels or status.overConsumeResource("energy", (self.maxEnergyUsage / self.chargeTime) * self.dt)) do
    chargeTimer = math.min(self.chargeTime, chargeTimer + self.dt)
    chargeLevel = self:setChargeLevel(chargeTimer, chargeLevel)
    coroutine.yield()
    end

    if chargeTimer > self.minChargeTime then
    self:setState(self.dash, chargeTimer / self.chargeTime)
    end
    end

    function Charge:dash(charge)
    self.weapon:setStance(self.stances.dash)
    self.weapon:updateAim()

    self:setLightning(3, self.dashLightning[1], self.dashLightning[2], self.dashLightning[3], self.dashLightning[4], 8)

    animator.burstParticleEmitter(self.weapon.elementalType .. "swoosh")
    animator.setAnimationState("swoosh", "fire")
    animator.setAnimationState("dashSwoosh", "full")
    animator.playSound("fire")

    util.wait(self.maxDashTime * charge, function(dt)
    local aimDirection = {mcontroller.facingDirection() * math.cos(self.weapon.aimAngle), math.sin(self.weapon.aimAngle)}
    mcontroller.controlApproachVelocity(vec2.mul(aimDirection, self.dashMaxSpeed), self.dashControlForce)
    mcontroller.controlParameters({
    airFriction = 0,
    groundFriction = 0,
    liquidFriction = 0,
    gravityEnabled = false
    })

    local damageArea = partDamageArea("dashSwoosh")
    self.damageConfig.baseDamage = self.baseDps * self.chargeTime * charge
    self.weapon:setDamage(self.damageConfig, damageArea)
    end)

    -- freeze in mid air for a short amount of time
    util.wait(self.freezeTime, function(dt)
    mcontroller.controlParameters({
    gravityEnabled = false
    })
    mcontroller.setVelocity({0,0})
    end)
    end

    function Charge:reset()
    activeItem.setScriptedAnimationParameter("lightning", {})
    animator.setAnimationState("dashSwoosh", "idle")
    end

    function Charge:uninit()
    self:reset()
    if self.weapon.currentState == self.dash then
    mcontroller.setVelocity({0,0})
    end
    end

    function Charge:setChargeLevel(chargeTimer, currentLevel)
    local level = math.min(self.chargeLevels, math.ceil(chargeTimer / self.chargeTime * self.chargeLevels))
    if currentLevel < level then
    local lightningCharge = self.lightningChargeLevels[level]
    self:setLightning(3, lightningCharge[1], lightningCharge[2], lightningCharge[3], lightningCharge[4], 2.75 + level)
    end
    return level
    end

    function Charge:setLightning(amount, width, forks, branching, color, length)
    local lightning = {}
    for i = 1, amount do
    local bolt = {
    minDisplacement = 0.125,
    forks = forks,
    forkAngleRange = 0.75,
    width = width,
    color = color,
    endPointDisplacement = -branching + (i * 2 * branching)
    }
    bolt.itemStartPosition = vec2.rotate(vec2.add(self.weapon.weaponOffset, {0, 4.0}), self.weapon.relativeWeaponRotation)
    bolt.itemEndPosition = vec2.rotate(vec2.add(self.weapon.weaponOffset, {0, 4.0 - length}), self.weapon.relativeWeaponRotation)
    bolt.displacement = vec2.mag(vec2.sub(bolt.itemEndPosition, bolt.itemStartPosition)) / 4
    table.insert(lightning, bolt)
    end
    activeItem.setScriptedAnimationParameter("lightning", lightning)
    end


    Edit: Already fixed the ability file calling for charge.lua rather than dragoon.lua, but that didn't fix it.
     

Share This Page