Modding Help [RESOLVED] "On/off" toggle for passive effect techs

Discussion in 'Starbound Modding' started by Ziz, Apr 2, 2016.

  1. Ziz

    Ziz Void-Bound Voyager

    I'm trying my best to stumble through lua and I want to think this is a simple thing to do, because I've looked at different mods and I'm at my wits' end:

    I want to make a tech that has an "on/off" toggle, where while "on," the player has a status effect cast on them. If the player hits the same key again while "on," the effect is removed and it's set back to "off." Let's use "glow" as an example: Tap "F" to glow indefinitely, tap "F" to stop glowing.

    I've tried looking at the code to this, for example, but there is no toggle that cancels the effect:

    I've also tried jacking code from the Skyrail tech since it has a similar "on/off" effect, but no dice either.

    Help? :<
  2. Errors4l

    Errors4l Spaceman Spiff

    I think this is what you're looking for:

    There's several ways to bind a tech key (F/G/H) to do what you want, the below code showing one example.
    Note that I've not tested the code and that the format of tech scripts will most likely change on the next stable update, making the input function obsolete.

    function input(args)
      if args.moves["special"] == 1 and not self.inputSpecial then
        self.inputSpecial = true
        return "toggleGlow"
      elseif args.moves["special"] == nil or args.moves["special"] ~= 1 then
        self.inputSpecial = false
      return nil
    function update(args)
        if args.actions["toggleGlow"] then
         self.glowing = not self.glowing
         if self.glowing then
           status.addEphemeralEffect("glow", math.huge) -- I don't know if there's a hack for an infinite duration.
    Ziz likes this.
  3. Ziz

    Ziz Void-Bound Voyager

    Oh wow, thank you! I gave it a whirl and it works like a charm. :)

    Thanks for the heads up as well. Hope I can cobble stuff together adequately before the next stable rollout.

Share This Page