Jump to content

Recommended Posts

Looking for a way to create a custom keybind, and have this keybind do something like, check the players current weapon (if they have one) or any other character thing.

 

 

So far I can link my keybind to widget player, but.... that player info does not include .components.inventory  or equippables, ect.

 

 

Seems to only have a name =/

 

 

Overall, if you have a good way to make a Keybind and a tut to follow for it, please help me out. Or even knowledge on how to direct the keybind to work with the player, with all their linked components.

Edited by JadeKnightblazer

@JadeKnightblazer, Without knowing more about exactly what you want the keybind to do, it's hard to say. But my guess is that you'll need to do some networking-- there isn't really a good way to do this yet (it's one of the things on the list to improve for mod support, I believe), but I think the best method right now is to hijack the RPC system with a custom action (as RPCs are the only way to do client->server communication, and the server is what has the components). I don't know much about how to do this, but it has been discussed in some other threads a while back.

 

However, a fair bit of information you can still get locally. Although the local character doesn't have inst.compnents.inventory, it does have inst.replica.inventory, for example.

I'll try the replica.inventory :)

 

here is what I am doing atm...

 

modMain:

local KEY_CTRL = GLOBAL.KEY_CTRLlocal TheInput = GLOBAL.TheInput--Key Bind stufflocal RELICKEY = GetModConfigData("RELICKEY")--Relic Toggle Keylocal controls = nillocal keydown = falselocal clientOwner = nil--Custom Relic Keylocal function ShowCastRelic()	if keydown then return end	keydown = true		--controls.relickey:CastRelic()	if clientOwner.prefab == "winston" then		--if clientOwner.components.inventory.equipslots[EQUIPSLOTS.BODY] == nil then			--local relicItem = clientOwner.components.inventory.equipslots[EQUIPSLOTS.HEAD]			--if relicItem.prefab == "skitemmealtickettest" then				clientOwner.components.talker:Say(clientOwner.prefab.." is equipped!")			--end		--end	end	endlocal function HideCastRelic()	keydown = false	endlocal function AddRelicToggleKey(self)	clientOwner = self.owner	controls = self -- this just makes controls available in the rest of the modmain's functions	--controls.relickey = controls:AddChild(RelicKey(self.owner))		GLOBAL.TheInput:AddKeyDownHandler(RELICKEY, ShowCastRelic)	GLOBAL.TheInput:AddKeyUpHandler(RELICKEY, HideCastRelic)		local OldOnUpdate = controls.OnUpdate	local function OnUpdate(...)		OldOnUpdate(...)		if keydown then			--self.relickey:CastRelic()		end	end	controls.OnUpdate = OnUpdateendAddClassPostConstruct( "widgets/controls", AddRelicToggleKey )

So far... I have a customizable Hotkey, using the Config.

 

Then you can press the RelicKey to command the clientOwner to check its prefab,  which will say a message. The --'s are just stuff that does not work atm.

Do you know what functions .replica.inventory  has? Can't seem to find a use for it.  Unless you ment inventory_replica
 inventory_replica is the file that has the code for the inventory replica, which is attached to the player table at replica.inventory. The same is true for all other replicable components.

@JadeKnightblazer, Because it's in your modmain, you need to call it from the GLOBAL space: GLOBAL.EQUIPSLOTS.BODY. This goes for anything defined globally, except for the specific things that are added to the mod environment (you can look at what's added in mods.lua, it's the part that has math, table, pairs, etc).

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...