Jump to content

Recommended Posts

Hello dearies,

Im currently trying to make a new structure that works very similar to the bee box, with one tad difference, it gives 1 additional item on the last stage
so it would give you 6 of X and 1 of Y
and now Im thinking how to acctually do that

Quote

local levels =
{
    { amount=6, idle="honey3", hit="hit_honey3" },
    { amount=3, idle="honey2", hit="hit_honey2" },
    { amount=1, idle="honey1", hit="hit_honey1" },
    { amount=0, idle="bees_loop", hit="hit_idle" },
}
-blah blah blah-
inst.components.harvestable:SetUp("honey", 6, nil, onharvest, updatelevel)

any help?
   

Edited by DragonflyTheGiant
last stage

@DragonflyTheGiant Gotchu fam ;) 

Spoiler

Just paste either one of these in to your modmain:


-- For just a single item of the secondary product

function HarvestableCompPostInit(comp)
	local old_Harvest = comp.Harvest

	comp.Harvest = function(self, picker)
		if self.inst.prefab == "<your structure>" and self.produce >= <# of produce needed> then
			local loot = GLOBAL.SpawnPrefab("<your extra item>")
			picker.components.inventory:GiveItem(loot)
		end
		return old_Harvest(self, picker)	-- must be returned for the actionfail callback
	end
end
AddComponentPostInit("harvestable", HarvestableCompPostInit)
          

-- For multiples of the secondary product

function HarvestableCompPostInit(comp)
	local old_Harvest = comp.Harvest

	comp.Harvest = function(self, picker)
		if self.inst.prefab == "<your structure>" and self.produce >= <# of produce needed> then
			local loot = GLOBAL.SpawnPrefab("<your extra item>")
			for i = 1, <num or variable of how many you want spawned> do
          			picker.components.inventory:GiveItem(loot)
        		end
		end
		return old_Harvest(self, picker)	-- must be returned for the actionfail callback
	end
end
AddComponentPostInit("harvestable", HarvestableCompPostInit)

 

Hope this helps!

Edited by w00tyd00d

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