Connall Posted February 3, 2014 Share Posted February 3, 2014 I've never quite ventured to this part of the forum, it's... nice. Anywho I'm trying to get into modding a little bit more, or at least in the case of Project Zomboid and for the most part I'm fine with LUA and all that. The thing I've never quite understood is how to utilise the Java Docs in relation to LUA. Anyway I'm trying to determine if an object that is right clicked on an inventory and it equals object x then the extra context menu will appear. To create the context menu I followed this guide: http://pz-mods.net/guide/how-to-create-inventory-context-menus/ However, it runs the extra context button on every single item. I don't want that, so I went into the Java Docs looking for something that would work. I found something to do with the InventoryItem and more specifically GetName() to hopefully return something simple, that I can use in an if statement to check the item. The problem is, I don't know how to use it in LUA. I imagine this is an incredibly noobish question and sorry about that, but this is a different world for me. I'm hoping that if I can get my head around Java Docs and how they are used in relation to LUA, I will have more information at my disposal, and hopefully create better mods, for it. Thanks all who take the time to read or reply. Link to comment Share on other sites More sharing options...
RoboMat Posted February 3, 2014 Share Posted February 3, 2014 Not sure what exactly you want to do, but to check for a certain item I use this (from my unpack bags mod):-- We iterate through the table of clicked items. We have -- to seperate between single items, stacks and expanded -- stacks. for i1 = 1, #itemTable do local item = itemTable[i1]; if instanceof(item, "InventoryItem") and instanceof(item, "InventoryContainer") thenAfter that you know that you have an InventoryItem AND InventoryContainer.To check from items based on their modules and Item names you could use this (from my story mod): elseif i > 1 and instanceof(clickedItem, "InventoryItem") then -- Unfolded stack. if clickedItem:getModule() == "MuldraughTales" then if clickedItem:getType () == "note" thenIf you want to use the java functions of an item you simply use ':' and the function call like this:item:getName()Hope that helps. Connall 1 Link to comment Share on other sites More sharing options...
Connall Posted February 3, 2014 Author Share Posted February 3, 2014 Not sure what exactly you want to do, but to check for a certain item I use this (from my unpack bags mod):-- We iterate through the table of clicked items. We have -- to seperate between single items, stacks and expanded -- stacks. for i1 = 1, #itemTable do local item = itemTable[i1]; if instanceof(item, "InventoryItem") and instanceof(item, "InventoryContainer") thenAfter that you know that you have an InventoryItem AND InventoryContainer.To check from items based on their modules and Item names you could use this (from my story mod):elseif i > 1 and instanceof(clickedItem, "InventoryItem") then -- Unfolded stack. if clickedItem:getModule() == "MuldraughTales" then if clickedItem:getType () == "note" thenIf you want to use the java functions of an item you simply use ':' and the function call like this:item:getName()Hope that helps.That's what I needed, thanks RoboMat Link to comment 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