i've been trying to fix the script of one of my tech and it looks like i can't find what's stopping it from doing any thing.... it is supposed to allow the user to take a monster in the air by clicking on it and move it to a different place. some images since images seems to explain things better than i do:http://imgur.com/UfKZ7Hd i've done my best to fix it but so far the only thing it does is consume energy and it find the position of the entity i'm pointing at. original code: Code: function init() data.active = false data.grabbed = false data.timer = 0 end function uninit() if data.active then tech.setParentFacingDirection(nil) end end function input(args) if args.moves["special"] == 1 then if not data.active then return "active" else return "inactive" end end if args.moves["primaryFire"] then return "grab" end if args.moves["down"] and tech.onGround() then return "crouch" end return nil end function update(args) local energyUsagePerSecond = tech.parameter("energyUsagePerSecond") local energyUsage = energyUsagePerSecond * args.dt local usedEnergy = 0 if not data.active and args.actions["active"] then tech.setToolUsageSuppressed(true) data.active = true elseif data.active and args.actions["inactive"] then tech.setToolUsageSuppressed(false) data.active = false end if data.active then local diff = world.distance(args.aimPosition, tech.position()) local aimAngle = math.atan2(diff[2], diff[1]) local flip = aimAngle > math.pi / 2 or aimAngle < -math.pi / 2 tech.setAnimationState("glowing", "low") if flip then tech.setFlipped(true) tech.setParentFacingDirection(-1) else tech.setFlipped(false) tech.setParentFacingDirection(1) end if args.actions["crouch"] then tech.setAnimationState("glowing", "crouch") end else tech.setAnimationState("glowing", "off") tech.setParentFacingDirection(nil) end if data.active and args.actions["grab"] and args.availableEnergy > energyUsage and data.timer <= 0 then local IDs = world.monsterQuery(args.aimPosition,5) table.insert(IDs, world.npcQuery(args.aimPosition,5)[1]) if IDs[1] ~= nil then local position = {} local velocity = {} position = world.entityPosition(IDs[1]) --world.logInfo("%d, %d", position[1], position[2]) velocity[1] = (args.aimPosition[1] - position[1]) * 10 velocity[2] = (args.aimPosition[2] - position[2]) * 10 world.callScriptedEntity(IDs[1], "entity.setVelocity", velocity) world.callScriptedEntity(IDs[1], "entity.setGravityEnabled", false) --world.monsterQuery(args.aimPosition,3, { callScript = "entity.setVelocity", callScriptArgs = { velocity } }) data.grabbed = true else world.monsterQuery(args.aimPosition,30, { callScript = "entity.setGravityEnabled", callScriptArgs = { true } }) data.grabbed = false end tech.setAnimationState("glowing", "low") return energyUsage elseif data.grabbed and (not args.actions["grab"] or args.availableEnergy < energyUsage) then data.timer = 1 world.monsterQuery(args.aimPosition,30, { callScript = "entity.setGravityEnabled", callScriptArgs = { true } }) --world.npcQuery(args.aimPosition,30, { callScript = "entity.setGravityEnabled", callScriptArgs = { true } }) tech.setAnimationState("glowing", "low") data.grabbed = false end data.timer = data.timer - args.dt return 0 end and this is what i've achived to do so far: Code: function init() self.active = false self.grabbed = false self.timer = 0 end function uninit() if self.active then mcontroller.controlFace(nil) end end function input(args) if args.moves["special"] == 1 then if not self.active then return "active" else return "inactive" end end if args.moves["primaryFire"] then return "grab" end if args.moves["down"] and mcontroller.onGround() then return "crouch" end return nil end function update(args) local energyUsagePerSecond = tech.parameter("energyUsagePerSecond") local energyUsage = energyUsagePerSecond * args.dt local usedEnergy = 0 if not self.active and args.actions["active"] then tech.setToolUsageSuppressed(true) self.active = true elseif self.active and args.actions["inactive"] then tech.setToolUsageSuppressed(false) self.active = false end if self.active then local diff = world.distance(tech.aimPosition(), mcontroller.position()) local aimAngle = math.atan2(diff[2], diff[1]) local flip = aimAngle > math.pi / 2 or aimAngle < -math.pi / 2 tech.setAnimationState("glowing", "low") if flip then tech.setFlipped(true) mcontroller.controlFace(-1) else tech.setFlipped(false) mcontroller.controlFace(1) end if args.actions["crouch"] then tech.setAnimationState("glowing", "crouch") end else tech.setAnimationState("glowing", "off") mcontroller.controlFace(nil) end if self.active and args.actions["grab"] and tech.consumeTechEnergy(energyUsage) and self.timer <= 0 then local IDs = world.monsterQuery(tech.aimPosition(),5) table.insert(IDs, world.npcQuery(tech.aimPosition(),5)[1]) if IDs[1] ~= nil then local position = {} local velocity = {} position = world.entityPosition(IDs[1]) --world.print("%d, %d", position[1], position[2]) velocity[1] = (tech.aimPosition()[1] - position[1]) * 10 velocity[2] = (tech.aimPosition()[2] - position[2]) * 10 world.callScriptedEntity(IDs[1], "entity.setVelocity", velocity) world.callScriptedEntity(IDs[1], "entity.setGravityEnabled", false) --world.monsterQuery(tech.aimPosition(),3, { callScript = "entity.setVelocity", callScriptArgs = { velocity } }) self.grabbed = true else world.monsterQuery(tech.aimPosition(),30, { callScript = "entity.setGravityEnabled", callScriptArgs = { true } }) self.grabbed = false end tech.setAnimationState("glowing", "low") return energyUsage elseif self.grabbed and (not args.actions["grab"] or tech.consumeTechEnergy(energyUsage)) then self.timer = 1 world.monsterQuery(tech.aimPosition(),30, { callScript = "entity.setGravityEnabled", callScriptArgs = { true } }) --world.npcQuery(tech.aimPosition(),30, { callScript = "entity.setGravityEnabled", callScriptArgs = { true } }) tech.setAnimationState("glowing", "low") self.grabbed = false end self.timer = self.timer - args.dt return 0 end
I finally found the patches.... here is the final code in case someone want's it... for some reason or an other. I've put in red the code that was changed form the original -----start of script----- function init() self.active = false self.grabbed = false self.timer = 0end function uninit() if self.active then mcontroller.controlFace(nil)endend function input(args) if args.moves["special"] == 1 then if not self.active then return "active"else return "inactive"endend if args.moves["primaryFire"] then return "grab"end if args.moves["down"] and mcontroller.onGround() then return "crouch"end return nilend function update(args) local energyUsagePerSecond = tech.parameter("energyUsagePerSecond") local energyUsage = energyUsagePerSecond * args.dt local usedEnergy = 0 if not self.active and args.actions["active"] then tech.setToolUsageSuppressed(true) self.active = trueelseif self.active and args.actions["inactive"] then tech.setToolUsageSuppressed(false) self.active = falseend if self.active then local diff = world.distance(tech.aimPosition(), mcontroller.position()) local aimAngle = math.atan2(diff[2], diff[1]) local flip = aimAngle > math.pi / 2 or aimAngle < -math.pi / 2 tech.setAnimationState("glowing", "low") if flip then tech.setFlipped(true) mcontroller.controlFace(-1)else tech.setFlipped(false) mcontroller.controlFace(1)end if args.actions["crouch"] then tech.setAnimationState("glowing", "crouch")endelse tech.setAnimationState("glowing", "off") mcontroller.controlFace(nil)end if self.active and args.actions["grab"] and tech.consumeTechEnergy(energyUsage) and self.timer <= 0 then local IDs = world.monsterQuery(tech.aimPosition(),5) table.insert(IDs, world.npcQuery(tech.aimPosition(),5)[1]) if IDs[1] ~= nil then local position = {} local velocity = {} position = world.entityPosition(IDs[1]) --world.print("%d, %d", position[1], position[2]) velocity[1] = (tech.aimPosition()[1] - position[1]) * 10 velocity[2] = (tech.aimPosition()[2] - position[2]) * 10 world.callScriptedEntity(IDs[1], "mcontroller.setVelocity", velocity) world.callScriptedEntity(IDs[1], "mcontroller.setGravityEnabled", false) --world.monsterQuery(tech.aimPosition(),3, { callScript = "mcontroller.setVelocity", callScriptArgs = { velocity } }) self.grabbed = trueelse world.monsterQuery(tech.aimPosition(),30, { callScript = "mcontroller.setGravityEnabled", callScriptArgs = { true } }) self.grabbed = falseend tech.setAnimationState("glowing", "low") return energyUsageelseif self.grabbed and (not args.actions["grab"] or tech.consumeTechEnergy(energyUsage)) then self.timer = 1 world.monsterQuery(tech.aimPosition(),30, { callScript = "mcontroller.setGravityEnabled", callScriptArgs = { true } }) --world.npcQuery(tech.aimPosition(),30, { callScript = "mcontroller.setGravityEnabled", callScriptArgs = { true } }) tech.setAnimationState("glowing", "low") self.grabbed = falseend self.timer = self.timer - args.dt return 0end -----end of script----- now i just need to fix the it toggling problem when i press f... it toggles and un-toggles continuously when i press to to toggle it[DOUBLEPOST=1419268754][/DOUBLEPOST] turns out that most of the entity.* has been moved to the mcontroller.* and btw doing world.logInfo("%s", mcontroller) crashes the tech script but yes the .entity did exits, it even had a page in the lua api wiki: http://starbounder.org/Modding:Lua/Tables/Entity#entity.setGravityEnabled
If I remember right this was one of the features of XS corporation mechs http://community.playstarbound.com/index.php?resources/xs-corporation-mechs.1341/ That might be a place to start looking as one of the mechs do exactly that As well ask the author for further assistance
it might do the same thing but since the last unstable update(the xs corporation mechs are still in enraged koala) most of the lua api has been revamped and most of the old script dosen't work anymore. i've been using this file that kawa put online to try to fix the script: http://helmet.kafuka.org/sbmods/diffs/20141217_to_stable.txt
I dont know if the entity.* commands you are sending in even exist anymore... I'm pretty sure the whole change to the movement controller kinda invalidated that entire thing. Sadly thats not something I have messed with yet so I cant give you any pointers on exactly how to fix it. But that would be where to start looking. Do me a favor and print out the mcontroler table and we can see its contents of which functions are in there now. I dont have access to the game right now, or I would do it for you: Code: function init() self.active = false self.grabbed = false self.timer = 0 world.logInfo("%s", mcontroller) end function uninit() if self.active then mcontroller.controlFace(nil) end end
I finally found the patches.... here is the final code in case someone want's it... for some reason or an other. I've put in red the code that was changed form the original -----start of script----- function init() self.active = false self.grabbed = false self.timer = 0end function uninit() if self.active then mcontroller.controlFace(nil)endend function input(args) if args.moves["special"] == 1 then if not self.active then return "active"else return "inactive"endend if args.moves["primaryFire"] then return "grab"end if args.moves["down"] and mcontroller.onGround() then return "crouch"end return nilend function update(args) local energyUsagePerSecond = tech.parameter("energyUsagePerSecond") local energyUsage = energyUsagePerSecond * args.dt local usedEnergy = 0 if not self.active and args.actions["active"] then tech.setToolUsageSuppressed(true) self.active = trueelseif self.active and args.actions["inactive"] then tech.setToolUsageSuppressed(false) self.active = falseend if self.active then local diff = world.distance(tech.aimPosition(), mcontroller.position()) local aimAngle = math.atan2(diff[2], diff[1]) local flip = aimAngle > math.pi / 2 or aimAngle < -math.pi / 2 tech.setAnimationState("glowing", "low") if flip then tech.setFlipped(true) mcontroller.controlFace(-1)else tech.setFlipped(false) mcontroller.controlFace(1)end if args.actions["crouch"] then tech.setAnimationState("glowing", "crouch")endelse tech.setAnimationState("glowing", "off") mcontroller.controlFace(nil)end if self.active and args.actions["grab"] and tech.consumeTechEnergy(energyUsage) and self.timer <= 0 then local IDs = world.monsterQuery(tech.aimPosition(),5) table.insert(IDs, world.npcQuery(tech.aimPosition(),5)[1]) if IDs[1] ~= nil then local position = {} local velocity = {} position = world.entityPosition(IDs[1]) --world.print("%d, %d", position[1], position[2]) velocity[1] = (tech.aimPosition()[1] - position[1]) * 10 velocity[2] = (tech.aimPosition()[2] - position[2]) * 10 world.callScriptedEntity(IDs[1], "mcontroller.setVelocity", velocity) world.callScriptedEntity(IDs[1], "mcontroller.setGravityEnabled", false) --world.monsterQuery(tech.aimPosition(),3, { callScript = "mcontroller.setVelocity", callScriptArgs = { velocity } }) self.grabbed = trueelse world.monsterQuery(tech.aimPosition(),30, { callScript = "mcontroller.setGravityEnabled", callScriptArgs = { true } }) self.grabbed = falseend tech.setAnimationState("glowing", "low") return energyUsageelseif self.grabbed and (not args.actions["grab"] or tech.consumeTechEnergy(energyUsage)) then self.timer = 1 world.monsterQuery(tech.aimPosition(),30, { callScript = "mcontroller.setGravityEnabled", callScriptArgs = { true } }) --world.npcQuery(tech.aimPosition(),30, { callScript = "mcontroller.setGravityEnabled", callScriptArgs = { true } }) tech.setAnimationState("glowing", "low") self.grabbed = falseend self.timer = self.timer - args.dt return 0end -----end of script----- now i just need to fix the it toggling problem when i press f... it toggles and un-toggles continuously when i press to to toggle it[DOUBLEPOST=1419268754][/DOUBLEPOST] turns out that most of the entity.* has been moved to the mcontroller.* and btw doing world.logInfo("%s", mcontroller) crashes the tech script but yes the .entity did exits, it even had a page in the lua api wiki: http://starbounder.org/Modding:Lua/Tables/Entity#entity.setGravityEnabled
Thats what I figured. Also you can fix the toggling continuously issue by saving the previous state of the keypress in the tech and check for it later. Code: function update(args) self.lastActive = self.activePress self.activePress = args.actions["active"] -- Toggle if self.activePress and not self.lastActive then -- If we enter this IF, then we toggled the button. Not holding it down. -- DO STUFF end end EDIT: Actually that would probably be better to wrap that around your Input() function for returning "active" and "inactive"
even by putting it around the if didn't help but i found how. Code: function init() self.active = false self.grabbed = false self.timer = 0 self.pressed = false end function uninit() if self.active then mcontroller.controlFace(nil) end end function input(args) if args.moves["special"] == 1 then if not self.pressed then self.pressed = true if not self.active then return "active" else return "inactive" end end else self.pressed = false end if args.moves["primaryFire"] then return "grab" end if args.moves["down"] and mcontroller.onGround() then return "crouch" end return nil end
I didnt mean quite literally... It was an example, not a copy paste solution. Either way, happy you got it working.