Marco98 Posted June 24, 2018 Share Posted June 24, 2018 (edited) Hi folks, i'm making a multi hand tool for my character that switches his function when i press a "binded key" for DST (ex: from pick-axe to a shovel, from a shovel to a sword and repeat); I'm not so good about this but for now i've already coded all the multi tool functions + the damage for the sword, but that goddamit change key... Hope to get some good help modinfo.lua modmain.lua omega.lua - update 1: i've found a mod called sneaky that have inside keybinds; how can i use these for my mod? (thx to Johnwatson) modinfo.lua Edited July 1, 2018 by Marco98 Link to comment https://forums.kleientertainment.com/forums/topic/92583-help-binding-a-key-that-change-characters-tool-properties/ Share on other sites More sharing options...
Poet737 Posted June 26, 2018 Share Posted June 26, 2018 (edited) I'm not really a coder but I do have an answer to one of your problems, maybe. For a keypress you can use: --You will need to create a new folder in your script folder, name it "components" without the "" and a new script called "keyhandler.lua" local KeyHandler = Class(function(self, inst) self.inst = inst self.handler = TheInput:AddKeyHandler(function(key, down) self:OnRawKey(key, down) end ) end) function KeyHandler:OnRawKey(key, down) local player = ThePlayer if (key and not down) and not IsPaused() then player:PushEvent("keypressed", {inst = self.inst, player = player, key = key}) elseif key and down and not IsPaused() then player:PushEvent("keydown", {inst = self.inst, player = player, key = key}) end end return KeyHandler --Keypress function local function OnKeyPressed(inst, data) if data.inst == ThePlayer then if data.key == KEY_X then --change KEY_X to whatever key you want to press if TheWorld.ismastersim then -- honestly not sure why I need this, but I believe it has to do with helping this work with caves or multiplayer on --put the code you want to perform here, in this case changing his state end end end end This code works for a project I'm using, so it should work for you hopefully. As for the rest, I hope someone else can assist you. Edited June 26, 2018 by Poet737 Clarity, broken piece of code Link to comment https://forums.kleientertainment.com/forums/topic/92583-help-binding-a-key-that-change-characters-tool-properties/#findComment-1056227 Share on other sites More sharing options...
Marco98 Posted June 26, 2018 Author Share Posted June 26, 2018 (edited) @Poet737 ok i will try this, thank you very much! Edited June 29, 2018 by Marco98 Link to comment https://forums.kleientertainment.com/forums/topic/92583-help-binding-a-key-that-change-characters-tool-properties/#findComment-1056268 Share on other sites More sharing options...
Marco98 Posted June 26, 2018 Author Share Posted June 26, 2018 (edited) @Poet737 i ve put this code and didn t work... what i ve done wrong? i m trying to change from Pick-axe to shovel but it won t work for me; Edited June 29, 2018 by Marco98 Link to comment https://forums.kleientertainment.com/forums/topic/92583-help-binding-a-key-that-change-characters-tool-properties/#findComment-1056302 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now