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: http://community.playstarbound.com/threads/invisibility.104663/ I've also tried jacking code from the Skyrail tech since it has a similar "on/off" effect, but no dice either. Help? :<
I think this is what you're looking for: http://www.sblaud.net/status.html#removeEphemeralEffect 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. Code: 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 end return nil end Code: 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. else status.removeEphemeralEffect("glow") end end end
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.