zazabar

  • Content Count

    18
  • Joined

  • Last visited

 Content Type 

Profiles

Forums

Downloads

Klei Bug Tracker

Game Updates

Hot Lava Bug Reporter

Everything posted by zazabar

  1. I'll take a look at this here in a minute Edit: Okay, took a look. Part of the problem is that you have the data for the writeables dissociated with the gravestones themselves. If you look in the beefalodomestication.lua, you'll see that they have the writeable data in the same file where it is being called. You don't have to do it directly like that, but right now there is nothing linking the information in your signs.lua. In fact, your gravesigns.lua calls the information from the original writeables, which doesn't contain anything for your signs. This is why it's crashing when you attempt to do anything with them. Hope this helps!
  2. So I revamped the entire thing based on your feedback. I got rid of the extra component and included all of the main primary functions without editing them. If you could look over this and see if you can find any other major flaws, it would be much appreciated! local require = GLOBAL.require GLOBAL.TUNING.NUMCROPROTATIONS = GetModConfigData("NumCropRotations") local function shoveled(inst, worker) inst.components.crop.matured = false inst.components.crop.growthpercent = 0 inst.components.crop.product_prefab = nil if inst.components.crop.grower ~= nil and inst.components.crop.grower:IsValid() and inst.components.crop.grower.components.grower ~= nil then inst.components.crop.grower.components.grower:RemoveCrop(inst) end inst.components.crop.grower = nil end local function AddWorkable(grower, plant) if grower.components.inspectable.nameoverride == "FARMPLOT" then plant:AddComponent("workable") plant.components.workable:SetWorkAction(GLOBAL.ACTIONS.DIG) plant.components.workable:SetWorkLeft(1) plant.components.workable:SetOnFinishCallback(shoveled) end end local function RemoveWorkable(grower, plant) if grower.components.inspectable.nameoverride == "FARMPLOT" then plant.inst:RemoveComponent("workable") end end AddComponentPostInit("grower", function(self) local oldPlantItem = self.PlantItem function self:PlantItem(item) local functionBool = false if self.inst.components.inspectable.nameoverride == "FARMPLOT" and item.components.plantable ~= nil then functionBool = oldPlantItem(self, item) self.curRotations = 0 return functionBool else return oldPlantItem(self, item) end end local oldOnSave = self.OnSave function self:OnSave() local mainData = oldOnSave(self) if self.inst.components.inspectable.nameoverride == "FARMPLOT" and self.curRotations ~= nil then mainData.cropTimerCurRotations = self.curRotations else mainData.cropTimerCurRotations = 0 end return mainData end local oldOnLoad = self.OnLoad function self:OnLoad(data, newents) oldOnLoad(self, data, newents) if self.inst.components.inspectable.nameoverride == "FARMPLOT" then self.curRotations = data.cropTimerCurRotations end end end) AddComponentPostInit("crop", function(self) local oldStartGrowing = self.StartGrowing function self:StartGrowing(prod, grow_time, grower, percent) oldStartGrowing(self, prod, grow_time, grower, percent) if grower.components.inspectable.nameoverride == "FARMPLOT" then AddWorkable(grower, self.inst) end end local oldHarvest = self.Harvest function self:Harvest(harvester) if self.grower.components.inspectable.nameoverride ~= "FARMPLOT" then return oldHarvest(self, harvester) end local tempItemProduct = self.product_prefab local tempCurRotations = self.grower.components.grower.curRotations + 1 local tempGrower = self.grower.components.grower local tempBoolean, tempPostProduct = oldHarvest(self, harvester) if tempCurRotations < GLOBAL.TUNING.NUMCROPROTATIONS then local tempItemPrefab = GLOBAL.SpawnPrefab("seeds") tempItemPrefab.components.plantable.product = tempItemProduct tempGrower.PlantItem(tempGrower, tempItemPrefab) tempGrower.curRotations = tempCurRotations end return tempBoolean, tempPostProduct end local oldResume = self.Resume function self:Resume() oldResume(self) AddWorkable(self.inst.components.crop.grower, self.inst) end end)
  3. Thanks! I'm a developer in the real world, so hearing stuff from other developers is always nice as well when it comes to stuff in other applications I don't know.
  4. Quick question. Trying to redo some of the code but I'm running into a weird crash that I'm having trouble solving. AddComponentPostInit("grower", function(self) local _old = self.PlantItem function self:PlantItem(item) return _old(item) end end) This is causing the program to crash, as it states that item is undefined. This happens when I try to plant a seed. I removed everything else and left just this, and it still crashes. "Attempt to index local 'item' (a nil value)" Am I missing an include or something?
  5. Thanks for the information! Wasn't aware you could do multiple declarations in one PostInit. That is definitely good to know. For the functions, yeah, in this case I couldn't just run them before or after. The code had to be inserted in specific points so I had to copy over the old code. I added the local old declarations at the start and forgot to remove them later.
  6. EDIT: Replaced code with updated code. If conversations after this don't make sense, that is why. Hey dere fellow modders! I wrote a new mod recently and I decided to do a write up on it to help others who are still new to modding (like myself) try to navigate through the system. The mod in question isn't too complicated. It adds two pieces of functionality. The first is that it allows 1-5 harvests of a crop from a single seed. What I mean by this is after you harvest the crop, instead of disappearing, it returns to growth level 0 and starts anew until X harvests have been reached. The second bit of functionality is the ability to use the shovel to remove said crop if you don't like what crop is growing for you. So let's get into it. The start: modinfo.lua --- This is going to be where we add the configuration options for the mod to access. There are already guides on how to write the general documentation, so I'm just going to talk about the configuration options themselves. configuration_options = { { name = "YourVariableName", description = "Your Variable Description", default = 4, --A default option out of the list to use. This is referring to the "data" variable and not the "description" variable. options = { { description = "1", data = 1, }, { description = "2", data = 2, }, { description = "3", data = 3, }, { description = "4", data = 4, }, { description = "5", data = 5, }, }, }, } Adding additional options is as simple as adding an additional {}, after the one before the last. In the case of my mod, the entire file looks like this: name = "Multiple Harvest Farms" description = "Allows you to get multiple harvests from a single seed. After picking your crop, the plant will return to 0 growth and start anew until it hits the set number of rotations." author = "zazabar" version = "1.0" forumthread = "" api_version = 10 priority = 1 --This lets the clients know that they need to download the mod before they can join a server that is using it. all_clients_require_mod = true --This let's the game know that this mod doesn't need to be listed in the server's mod listing client_only_mod = false --Let the mod system know that this mod is functional with Don't Starve Together dont_starve_compatible = false reign_of_giants_compatible = false dst_compatible = true --These tags allow the server running this mod to be found with filters from the server listing screen server_filter_tags = {"farm","crop","plant"} icon_atlas = "preview.xml" icon = "preview.tex" configuration_options = { { name = "NumCropRotations", description = "Number of Crop Rotations", default = 4, options = { { description = "1", data = 1, }, { description = "2", data = 2, }, { description = "3", data = 3, }, { description = "4", data = 4, }, { description = "5", data = 5, }, }, }, } In order for your component to get the configuration data from the mod, you'll need to use the GetModConfigData" function, which will pull it based on the name you gave it in the modinfo.lua file. Now for the meat: modmain.lua --- local require = GLOBAL.require GLOBAL.TUNING.NUMCROPROTATIONS = GetModConfigData("NumCropRotations") local function shoveled(inst, worker) inst.components.crop.matured = false inst.components.crop.growthpercent = 0 inst.components.crop.product_prefab = nil if inst.components.crop.grower ~= nil and inst.components.crop.grower:IsValid() and inst.components.crop.grower.components.grower ~= nil then inst.components.crop.grower.components.grower:RemoveCrop(inst) end inst.components.crop.grower = nil end local function AddWorkable(grower, plant) if grower.components.inspectable.nameoverride == "FARMPLOT" then plant:AddComponent("workable") plant.components.workable:SetWorkAction(GLOBAL.ACTIONS.DIG) plant.components.workable:SetWorkLeft(1) plant.components.workable:SetOnFinishCallback(shoveled) end end local function RemoveWorkable(grower, plant) if grower.components.inspectable.nameoverride == "FARMPLOT" then plant.inst:RemoveComponent("workable") end end AddComponentPostInit("grower", function(self) local oldPlantItem = self.PlantItem function self:PlantItem(item) local functionBool = false if self.inst.components.inspectable.nameoverride == "FARMPLOT" and item.components.plantable ~= nil then functionBool = oldPlantItem(self, item) self.curRotations = 0 return functionBool else return oldPlantItem(self, item) end end local oldOnSave = self.OnSave function self:OnSave() local mainData = oldOnSave(self) if self.inst.components.inspectable.nameoverride == "FARMPLOT" and self.curRotations ~= nil then mainData.cropTimerCurRotations = self.curRotations else mainData.cropTimerCurRotations = 0 end return mainData end local oldOnLoad = self.OnLoad function self:OnLoad(data, newents) oldOnLoad(self, data, newents) if self.inst.components.inspectable.nameoverride == "FARMPLOT" then self.curRotations = data.cropTimerCurRotations end end end) AddComponentPostInit("crop", function(self) local oldStartGrowing = self.StartGrowing function self:StartGrowing(prod, grow_time, grower, percent) oldStartGrowing(self, prod, grow_time, grower, percent) AddWorkable(grower, self.inst) end local oldHarvest = self.Harvest function self:Harvest(harvester) if self.grower.components.inspectable.nameoverride ~= "FARMPLOT" then return oldHarvest(self, harvester) end local tempItemProduct = self.product_prefab local tempCurRotations = self.grower.components.grower.curRotations + 1 local tempGrower = self.grower.components.grower local tempBoolean, tempPostProduct = oldHarvest(self, harvester) if tempCurRotations < GLOBAL.TUNING.NUMCROPROTATIONS then local tempItemPrefab = GLOBAL.SpawnPrefab("seeds") tempItemPrefab.components.plantable.product = tempItemProduct tempGrower.PlantItem(tempGrower, tempItemPrefab) tempGrower.curRotations = tempCurRotations end return tempBoolean, tempPostProduct end local oldResume = self.Resume function self:Resume() oldResume(self) AddWorkable(self.inst.components.crop.grower, self.inst) end end) There's a lot here so let's step through it. First, we need global data so we do a local require which specifies the GLOBAL data. Next, we assign our variable to the GLOBAL.TUNING area so that it can be modified by outside processes if necessary and so we don't have to make multiple calls to find it. Function shoveled - This function is what decides what happens to our crop when we use the shovel on it. It's required to have a callback function whenever you have something workable. Functions AddWorkable and RemoveWorkable - These two functions are what we use to add and remove the workable status from our crop. We want to make sure that we don't apply this to non-farm crops, so we do a quick check to make sure they are a part of that. Grower PostInit Function PlantItem - Once again, we want to make sure this only applies to farms. If it doesn't, just return the old function. Whenever possible we want to use the old functions for maximum compatibility, so we run the old function then add our extra variable before returning. Grower PostInit Function OnSave and OnLoad - We want to keep our data for the farms when we close the game or reopen it, so we need to have these two functions. Once again, call old functions whenever possible and then add our data before returning. Make sure the main format of the data doesn't change or the game might crash. We have the addition of the workable part in the crop portion later. Crop PostInit Function StartGrowing - Very simple, call the old function then add our workable. Crop PostInit Function Harvest - This function was slightly trickier. We want to run the old function, but when we do so, we inadvertently clear out all of the information about the crop from the grower. So to get around this, we need to get a couple of variables first then run the original function. After, we generate a new seed with the same product to throw back into the farm. Since the PlantItem function cleans up the seed prefab we generated, we don't have to worry about doing anything with it. Crop PostInit Function Resume - This function just adds our workable function to the crop. The reason it is here and not in the grower function is because it's actually troublesome to pull crops directly from the farmplot. ----------- And that's everything. I hope it helps someone!
  7. Couple super quick questions. If you have prefabs in your mods /prefabs/ directory, are they loaded automatically? I've noticed a couple mods that have empty modmain files but prefabs and they work fine so I'm assuming it loads everything into memory regardless? If so, does this only happen if modmain is empty? Assuming the above, using prefabs that already exist overwrite the old prefabs, right? (Looking at Animal Variety and it looks like it just overwrites the original prefabs.)
  8. As long as you are crediting the original author, I don't see a problem with it. That's part of the point of open source modding. People can iterate on each other, especially when a mod is abandoned.