Modding Help ON / OFF Toggle LUA script With Keybind

Discussion in 'Starbound Modding' started by captainrumbarrels, Feb 16, 2018.

  1. captainrumbarrels

    captainrumbarrels Phantasmal Quasar

    Can anyone give me guidance in lua scripting?

    I'm attempting to make a simple toggle on/off switch much like the flashlight. As a matter of fact I'm using the flashlight as a template except it toggles a status effect when a certain key is pressed for an item. This is not a weapon ability and this is not a tech item. I'm making progress with learning lua. However I'm uncertain how to accomplish this. My main setback is knowing what variables and syntax that the game uses.

    Any Ideas?

    SOLVED: Managed to make a heavily modified Flashlight.lua file where I removed everything except the content within the update function. Plus the starbound wiki has a library of variables and operators which I don't see many people referencing. Here in this example below the user gains a boost of speed in their weapons aiming direction as an alt fire ability. Glad I managed to figure this out. Removing the self.lastFireMode = fireMode at the end turns the weapon from a toggle to a "hold" alt fire behavior. If people want to modify this script to do anything they like for weapon abilities they are welcome to do so. Otherwise I would suggest using the flashlight.lua as a starting point.

    function Speedboost:update(dt, fireMode, shiftHeld)
      WeaponAbility.update(self, dt, fireMode, shiftHeld)
      if self.fireMode == "alt"
      and self.lastFireMode ~= "alt"
      and not status.resourceLocked("energy") then
      -- and mcontroller.facingDirection() == 1 then = not
        status.overConsumeResource("energy", 40)
          local boostAngle = mcontroller.facingDirection() == -1 and -self.weapon.aimAngle - math.pi or self.weapon.aimAngle
          mcontroller.controlApproachVelocityAlongAngle(boostAngle, 1500, 7000, true)
        mcontroller.setXVelocity(0, 100)
        mcontroller.setYVelocity(0, 100)
      self.lastFireMode = fireMode
    Last edited: Mar 19, 2018

Share This Page