void222x Posted April 9, 2015 Share Posted April 9, 2015 Hello folks. I have recently made a drop button mod to drop one item at a time from a stack on the keyboard controls. Essential I would have keys assigned to moving left and right on the inventory and then pressing a key drop the item I would want. What I'am trying to do now is make it so I don't have to press keys to move left and right on the toolbar and just drop the item that is currently being highlighted by the mouse cursor. In Invslot.lua I Imported the CONTROL_DROP_ITEM from playercontroller.lua. While I can still drop my item by pressing a hotkey, I cannot drop it when I'm highlighting a slot on the inventory which is telling me that its working but I seem to need a variable of some sort inside the "()" on "self.owner.components.inventory:DropItem()" I have tried calling variables for inv_obj and inv_item but I would get the NIL errors when doing this. If anyone can let me know what my next step with this would be, It would be much appreciated! Thanks!function InvSlot:OnControl(control, down) if InvSlot._base.OnControl(self, control, down) then return true end if down then if control == CONTROL_ACCEPT then --generic click, with possible modifiers if TheInput:IsControlPressed(CONTROL_FORCE_INSPECT) then self:Inspect() else if TheInput:IsControlPressed(CONTROL_FORCE_TRADE) then self:TradeItem(TheInput:IsControlPressed(CONTROL_FORCE_STACK)) else self:Click(TheInput:IsControlPressed(CONTROL_FORCE_STACK)) end end elseif control == CONTROL_SECONDARY and self.tile and self.tile.item then --alt use (usually RMB) GetPlayer().components.inventory:UseItemFromInvTile(self.tile.item) -- the rest are explicit control presses for controllers elseif control == CONTROL_SPLITSTACK then self:Click(true) elseif control == CONTROL_TRADEITEM then self:TradeItem(false) elseif control == CONTROL_TRADESTACK then self:TradeItem(true) elseif control == CONTROL_INSPECT then self:Inspect() elseif control == CONTROL_INVENTORY_DROP then self.owner.components.inventory:DropItem() else return false end return true endend Link to comment Share on other sites More sharing options...
Blueberrys Posted April 9, 2015 Share Posted April 9, 2015 @void222x Yeah, the DropItem function requires the first parameter to be an inventory item's instance.Reference (inventory.lua)function Inventory:DropItem(item, wholestack, randomdir, pos) if not item or not item.components.inventoryitem then return end local dropped = item.components.inventoryitem:RemoveFromOwner(wholestack) or item if dropped then pos = pos or Vector3(self.inst.Transform:GetWorldPosition()) --print("Inventory:DropItem", item, pos) dropped.Transform:SetPosition(pos:Get()) if dropped.components.inventoryitem then dropped.components.inventoryitem:OnDropped(randomdir) end self.inst:PushEvent("dropitem", {item = dropped}) end return droppedend You can get the currently active item:local item = self.owner.components.inventory.activeitemif item then self.owner.components.inventory:DropItem(item)end Link to comment Share on other sites More sharing options...
void222x Posted April 10, 2015 Author Share Posted April 10, 2015 Thank you very much for your help man! I got it working now! quick question though. If I wanted to drop the item while my cursor is not in the inventory what would I do? If I click the item and hold it over the inventory slot I can drop it but if I hover the item out of the inventory II can't. Is this because there is a drop already programmed for the mouse when you have the item outside the inventory? Link to comment Share on other sites More sharing options...
Blueberrys Posted April 10, 2015 Share Posted April 10, 2015 @void222x Hmm. I'm not sure if I understood the question correctly. Judging by the code, whatever you're doing here is apparently only affecting InvSlot. You would need to modify something else if you want it to work differently. Logically, changing InvSlot:OnControl only affects the inventory slot. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.