Onkeen Posted August 24, 2013 Share Posted August 24, 2013 Hello everybody I have one fast question : I have found that everything about building recipes is located in tis quite big lua file : ProjectZomboid\media\lua\BuildingObjects\ISUI\ISBuildMenu.lua I am wondering, "how could I add recipes to this menu without messing up with the original code ?" I mean, ther is instructions to make a recipe but what do i have to do to make my mod lua file add something to the menu without changing the ISBuildMenu.lua file ? --------------------------------------------------------------------------------------------------------------------------------------------------- After some work I've finally made a sub menu in the build mune and manage to increase the restriction of carpentry level to 4... But I have change the original code to make it. And I don'twant to modify the original code. I've add this :-- line 82 ------------------ Chevilles ------------------local chevilleOption = subMenu:addOption("Chevilles", worldobjects, nil);local subMenuCheville = subMenu:getNew(subMenu);-- we add our new menu to the option we want (here build)context:addSubMenu(chevilleOption, subMenuCheville);ISBuildMenu.buildChevilleMenu(subMenuCheville, context, player); and this :-- line 439-- **********************************************-- ** *Chevilles* **-- **********************************************ISBuildMenu.buildChevilleMenu = function(subMenu, context, player) -- The Cheville Wall local sprite = ISBuildMenu.getWoodenWallSprites(player); local wallOption = subMenu:addOption("Wooden Wall", worldobjects, ISBuildMenu.onWoodenWall, square, sprite); local tooltip = ISBuildMenu.canBuild(3, 3, 0, 0, 0, 4, wallOption, player); tooltip:setName("Wooden Wall"); tooltip.description = "A simple wooden wall, can be barricaded, plastered and painted " .. tooltip.description; tooltip:setTexture(sprite.sprite);end-- create a wall to drag a ghost render of the wall under the mouseISBuildMenu.onWoodenWall = function(worldobjects, square, sprite) -- sprite, northSprite, corner local wall = ISWoodenWall:new(sprite.sprite, sprite.northSprite, sprite.corner); wall.canBePlastered = true; wall.modData["plasterTile"] = "TileWalls_52"; wall.modData["plasterTileNorth"] = "TileWalls_53"; wall.modData["PaintTurquoise"] = "TileWalls_36"; wall.modData["PaintTurquoiseNorth"] = "TileWalls_37"; wall.modData["PaintYellow"] = "TileWalls_4"; wall.modData["PaintYellowNorth"] = "TileWalls_5"; wall.modData["PaintPurple"] = "TileWalls_20"; wall.modData["PaintPurpleNorth"] = "TileWalls_21"; wall.modData["PaintWhite"] = "TileWalls_52"; wall.modData["PaintWhiteNorth"] = "TileWalls_53"; wall.modData["PaintCyan"] = "TileWalls3_0"; wall.modData["PaintCyanNorth"] = "TileWalls3_1"; wall.modData["PaintBlue"] = "TileWalls3_4"; wall.modData["PaintBlueNorth"] = "TileWalls3_5"; wall.modData["PaintOrange"] = "TileWalls3_16"; wall.modData["PaintOrangeNorth"] = "TileWalls3_17"; wall.modData["PaintBrown"] = "TileWalls3_20"; wall.modData["PaintBrownNorth"] = "TileWalls3_21"; wall.modData["PaintLightBrown"] = "TileWalls3_36"; wall.modData["PaintLightBrownNorth"] = "TileWalls3_37"; wall.modData["PaintLightBlue"] = "TileWalls3_52"; wall.modData["PaintLightBlueNorth"] = "TileWalls3_53"; wall.modData["PaintPink"] = "TileWalls4_4"; wall.modData["PaintPinkNorth"] = "TileWalls4_5"; wall.modData["PaintGreen"] = "TileWalls4_48"; wall.modData["PaintGreenNorth"] = "TileWalls4_49"; -- set up the required material wall.modData["need:Base.Plank"] = "3"; wall.modData["need:Base.Nails"] = "3"; getCell():setDrag(wall);endBut can someone help me to make it be a lua mod file ? Link to comment Share on other sites More sharing options...
RoboMat Posted August 24, 2013 Share Posted August 24, 2013 Well you could overwrite the original carpentry functions in your modfile. This is recommended because if people want to deinstall your mod they don't need to reinstall it (it doesn't break the vanilla game) E.g.: require 'theCarpentryFile' function SameNameAsTheOriginalFunction() .... your code end Link to comment Share on other sites More sharing options...
Onkeen Posted August 24, 2013 Author Share Posted August 24, 2013 Thanks ! I'll try it and tell you what happens... ------------------------------------------------------------------------------------------------------------------------------------------------- Edit ! I am trying to add a submenu to the building menu table. I have respected th syntax you told me above but my mod won't launch. Here is the thing, I want to add a menu to this code : -- build menu -- if we have any thing to build in our inventory if ISBuildMenu.haveSomethingtoBuild(player) then local buildOption = context:addOption("Build", worldobjects, nil); -- create a brand new context menu wich contain our different material (wood, stone etc.) to build local subMenu = ISContextMenu:getNew(context); -- We create the different option for this new menu (wood, stone etc.) -- check if we can build something in wood material if haveSomethingtoBuildWood(player) then -- we add the subMenu to our current option (Build) context:addSubMenu(buildOption, subMenu); ------------------ WALL ------------------ ISBuildMenu.buildWallMenu(subMenu, player); ------------------ DOOR ------------------ local doorOption = subMenu:addOption("Door", worldobjects, nil); local subMenuDoor = subMenu:getNew(subMenu); -- we add our new menu to the option we want (here door) context:addSubMenu(doorOption, subMenuDoor); ISBuildMenu.buildDoorMenu(subMenuDoor, player); ------------------ DOOR FRAME ------------------ ISBuildMenu.buildDoorFrameMenu(subMenu, player);--~ ----------------- WINDOWS FRAME----------------- ISBuildMenu.buildWindowsFrameMenu(subMenu, player);--~ ------------------ STAIRS ------------------ local stairsOption = subMenu:addOption("Stairs", worldobjects, nil); local subMenuStairs = subMenu:getNew(subMenu); -- we add our new menu to the option we want (here wood) context:addSubMenu(stairsOption, subMenuStairs); ISBuildMenu.buildStairsMenu(subMenuStairs, player);--~ ------------------ FLOOR ------------------ local floorOption = subMenu:addOption("Floor", worldobjects, nil); local subMenuFloor = subMenu:getNew(subMenu); -- we add our new menu to the option we want (here build) context:addSubMenu(floorOption, subMenuFloor); ISBuildMenu.buildFloorMenu(subMenuFloor, player); ------------------ WOODEN CRATE ------------------ ISBuildMenu.buildContainerMenu(subMenu, player); ------------------ BAR ------------------ local barOption = subMenu:addOption("Bar", worldobjects, nil); local subMenuBar = subMenu:getNew(subMenu); -- we add our new menu to the option we want (here wood) context:addSubMenu(barOption, subMenuBar); ISBuildMenu.buildBarMenu(subMenuBar, player); ------------------ FURNITURE ------------------ local furnitureOption = subMenu:addOption("Furniture", worldobjects, nil); local subMenuFurniture = subMenu:getNew(subMenu); -- we add our new menu to the option we want (here build) context:addSubMenu(furnitureOption, subMenuFurniture); ISBuildMenu.buildFurnitureMenu(subMenuFurniture, context, player); ------------------ FENCE ------------------ local fenceOption = subMenu:addOption("Fence", worldobjects, nil); local subMenuFence = subMenu:getNew(subMenu); -- we add our new menu to the option we want (here build) context:addSubMenu(fenceOption, subMenuFence); ISBuildMenu.buildFenceMenu(subMenuFence, player); end endSo my mod look like that now with your tips :require 'BuildingObjects\ISUI\ISBuildMenu'-- -------------------------------------------------- Functions-- ------------------------------------------------ function haveSomethingtoBuildWood() ------------------ Dowels Crafts ------------------ local dowelOption = subMenu:addOption("With dowels", worldobjects, nil); local subMenuDowel = subMenu:getNew(subMenu); -- for the moment I'm just trying to add a new menu, this one should show a wall menu -- with a different name. context:addSubMenu(dowelOption, subMenuDowel); ISBuildMenu.buildWallMenu(subMenuDowel, context, player); end-- -------------------------------------------------- Game hooks-- ------------------------------------------------Events.OnGameBoot.Add(haveSomethingtoBuildWood);But it still don't work, The log error is : stack : havesomethingtobuildwoodattempted index: add0ption of non-table: nullMod Loaded : Wooden Dowel CraftsI think that's because i'm using the wrong funtion but I don't know which one I should be using :/ Link to comment Share on other sites More sharing options...
RoboMat Posted August 24, 2013 Share Posted August 24, 2013 You must overwrite the complete ISBuildMenu.haveSomethingToBuild(player). Copy its syntax to your own lua file and add the stuff you want to mod. The error only tells you that the table subMenu can't be found so you can't call a function from it. This happens because subMenu is declared in the ISBuildMenu.haveSomethingToBuild(player) function. The function you overwrite doesn't have anything to do with the buildng menu (I think it's just an utility function that looks for building material). Link to comment Share on other sites More sharing options...
Onkeen Posted August 24, 2013 Author Share Posted August 24, 2013 Uh okey... I think I've just understand how modding work or maybe not x) But buy playin with lines, I managed to resolve my problem, but now I had to replace the nails by something else... any leads or idea ? because the function is declared like that :ISBuildMenu.canBuild = function(plankNb, nailsNb, hingeNb, doorknobNb, baredWireNb, carpentrySkill, option, player)But I would like to use something else... Should I use the exception method like for drawers and set nails at 0 or is there a way to replace nailsNb by my custom item ? EDIT : I solved my problem alone, I just needed to replace every "Nails" reference with "WoodDowel" Link to comment Share on other sites More sharing options...
RoboMat Posted August 24, 2013 Share Posted August 24, 2013 Uh okey... I think I've just understand how modding work or maybe not x) But buy playin with lines, I managed to resolve my problem, but now I had to replace the nails by something else... any leads or idea ? because the function is declared like that :ISBuildMenu.canBuild = function(plankNb, nailsNb, hingeNb, doorknobNb, baredWireNb, carpentrySkill, option, player)But I would like to use something else... Should I use the exception method like for drawers and set nails at 0 or is there a way to replace nailsNb by my custom item ? EDIT : I solved my problem alone, I just needed to replace every "Nails" reference with "WoodDowel" Cool, but make sure that the vanilla functions still work Link to comment Share on other sites More sharing options...
Onkeen Posted August 24, 2013 Author Share Posted August 24, 2013 You are right ! the original menu is now fuck up ! even if i've made a second menu for thedowel building... Duh so close EDIT : still not fixed... I've manage to get back the "nails" in the original crafing menu but the menu tell me that I have not the items requied... But in facts I have them, how could I fix that kind of bug In fact I have created a parallel "ISBuildMenu2" in my mod but it seems to take the advantage on the original and makes the original menu here but always showing tha I hav'nt the material with me :/ But the 6 planks are detected by the Builld with Dowels menu :/ REDIT : FIXED IT ON MY OWN ! Dude I'm on a row now ! I'm getting more and more familiar with this lua thing ahah ! It wasn't working because I was using the same : "haveSomethingtoBuild" function as the vanilla building menu ! REREDIT : Hey hey check this out, the mod is now finished and even posted on your website http://pz-mods.net/weapons-items/WoodenDowels/ Aricane 1 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