Jump to content

Recommended Posts

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 by Marco98

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 by Poet737
Clarity, broken piece of code

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...