Modding Help Adding light to a weapon?

Discussion in 'Starbound Modding' started by haynesy566, Jun 10, 2015.

  1. haynesy566

    haynesy566 Heliosphere

    Hi all,

    I was curious on how I would go about adding light to a weapon, I need the same sort of light level as a flashlight but the beam needs to be 180 degrees (its for my holdable torch mod)

    Looking forward to some advice

    Thanks guys! :D
     
  2. lazarus78

    lazarus78 The Waste of Time

  3. haynesy566

    haynesy566 Heliosphere

    Thanks @lazarus78

    I wanted to improve the position of the torch so I figured that if i made it a weapon, it'd have a more natural movement, guess I'll wait till the next major update...
     
  4. The | Suit

    The | Suit Agent S. Forum Moderator

    The only way possible is to add it through lua.

    With that said - the basic concept is below to see how guns are modified through animators.
    Code:
    function init()
      self.fireOffset = item.instanceValue("fireOffset")
      updateAim()
      self.active = false
      storage.fireTimer = storage.fireTimer or 0
      self.recoilTimer = 0
    end
    function update(dt, fireMode, shiftHeld)
      updateAim()
      if fireMode == "none" then
        stopFiring()
      end
      storage.fireTimer = math.max(storage.fireTimer - dt, 0)
      self.recoilTimer = math.max(self.recoilTimer - dt, 0)
      if self.active and storage.fireTimer <= 0 then
        if not world.pointTileCollision(firePosition()) then
          storage.fireTimer = item.instanceValue("fireTime", 1.0)
          fire()
        end
      end
      activeItem.setRecoil(self.recoilTimer > 0)
    end
    function activate(fireMode, shiftHeld)
      if not self.active then
        startFiring()
      end
    end
    function startFiring()
      self.active = true
    end
    function stopFiring()
      self.active = false
    end
    function fire()
      world.spawnProjectile(
          item.instanceValue("projectileType"),
          firePosition(),
          activeItem.ownerEntityId(),
          aimVector(),
          false,
          item.instanceValue("projectileParameters", {})
        )
      animator.burstParticleEmitter("fireParticles")
      animator.playSound("fire")
      animator.setAnimationState("reload", "reload", true)
      self.recoilTimer = 0.12
    end
    function updateAim()
      self.aimAngle, self.aimDirection = table.unpack(activeItem.aimAngleAndDirection(self.fireOffset[2], activeItem.ownerAimPosition()))
      activeItem.setArmAngle(self.aimAngle)
      activeItem.setFacingDirection(self.aimDirection)
    end
    function firePosition()
      return vec2.add(mcontroller.position(), activeItem.handPosition(self.fireOffset))
    end
    function aimVector()
      local aimVector = vec2.rotate({1, 0}, self.aimAngle + sb.nrand(item.instanceValue("inaccuracy", 0), 0))
      aimVector[1] = aimVector[1] * self.aimDirection
      return aimVector
    end
     
    haynesy566 likes this.
  5. haynesy566

    haynesy566 Heliosphere

    So for this to work would the player constantly have to press the "fire" button to generate light?
     
  6. lazarus78

    lazarus78 The Waste of Time

    almost looks like it works wen you aren't firing.
     
    haynesy566 likes this.
  7. haynesy566

    haynesy566 Heliosphere

    Well to be honest, I'm a noob at lua so I'll just wait until I'm a little more experienced...
     
    Kayuko likes this.

Share This Page