D4rkh0bb1T Posted March 26, 2016 Share Posted March 26, 2016 Hello! I was successful in the creation of my Mushroom Farm so far. I want it to "level up" using seg time and to be able to gather more mushrooms from it after 3 days for exemple. I saw a lot of mods doing this (silk farm, fish farm, bee box...). I created the Recipe Tab, all images are in the right folder. In game, I can craft it and place it on the ground. In my spriter project, I created 4 animations : Idle, mush1, mush2 and mush3 ! The compiler made my .zip animation file and when I look at it, it contains my 4 images. When placing the farm, the first animation showing up is the Idle Animation, which is fine at the beginning. Then, I can harvest from it (considering its the 1st level - mush1) but the animation is still Idle, not showing up the proper Animation, which should be mush1, (then level 2 = mush2, etc.) When the level is at max and ready to be fully harvested, the animation changes, showing up mush1 instead of mush3 0_o Not only the animation does not fit the level, but I can only harvest one item. The harvest setup goes like this : SetUp(product, max, time, onharvest, ongrow). How do I make the product to become 3 mushrooms instead of 1? I tried to add three lines (for the three mushrooms) of SetUp, but the game picked the blue_cap, maybe cause it .... may be cause I dont know why. So... I can't get the right animation according to its level, but the game picks mush1 on the last level instead of mush3. I can't get more than one type of item when harvesting my farm - I'd like to harvest the three types of mushrooms in the game, but the game prefers blue_cap hehe I'll show my codes, maybe someone can help me out! Thanx in advance, I'm really stucked. Modmain part: Spoiler local seg_time = 1 --FOR TESTING local total_day_time = seg_time*16 TUNING.NORMAL_AMOUNT = 3 TUNING.NORMAL_TIME = seg_time*16 Mushroomfarm part : Spoiler PrefabFiles = { "mushroomfarm", "red_cap", "blue_cap", "green_cap", } local levels = { { amount=9, idle="mush3",true }, { amount=6, idle="mush2",true }, { amount=3, idle="mush1",true }, { amount=0, idle="idle",true }, } local function setlevel(inst, level) if not inst.anims then inst.anims = {idle = level.idle} else inst.anims.idle = level.idle end inst.AnimState:PlayAnimation(inst.anims.idle,false) end local function updatelevel(inst) for k,v in pairs(levels) do if inst.components.harvestable.produce >= v.amount then setlevel(inst, v) break end end end local function onharvest(inst) updatelevel(inst) end local function OnLoad(inst, data) updatelevel(inst) end local function onbuilt(inst) inst.AnimState:PlayAnimation("idle") inst.AnimState:PushAnimation("idle", false) end local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() inst.entity:AddSoundEmitter() MakeObstaclePhysics(inst, 1.8) inst.AnimState:SetBank("mushroomfarm") inst.AnimState:SetBuild("mushroomfarm") inst.AnimState:PlayAnimation("idle") local minimap = inst.entity:AddMiniMapEntity() minimap:SetIcon( "mushroomfarm.tex" ) --64x64 png inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("harvestable") inst.components.harvestable:SetUp("red_cap", TUNING.NORMAL_AMOUNT, TUNING.NORMAL_TIME, onharvest, updatelevel) inst.components.harvestable:StartGrowing() inst:AddComponent("inspectable") inst.components.inspectable.getstatus = function(inst) if inst.components.harvestable:CanBeHarvested() then return "READY" end end inst:AddComponent("lootdropper") inst:AddComponent("workable") inst.components.workable:SetWorkAction(ACTIONS.HAMMER) inst.components.workable:SetWorkLeft(4) inst.components.workable:SetOnFinishCallback(onhammered) inst.components.workable:SetOnWorkCallback(onhit) updatelevel(inst) MakeSnowCovered(inst, .01) inst:ListenForEvent( "onbuilt", onbuilt) inst:ListenForEvent( "onharvest", updatelevel) inst.OnLoad = OnLoad return inst end return Prefab( "common/mushroomfarm", fn, assets, prefabs) D4rkh0bb1T Link to comment Share on other sites More sharing options...
Mobbstar Posted March 26, 2016 Share Posted March 26, 2016 @D4RKH013 you need to raise TUNING.NORMAL_AMOUNT to 9 if you want nine mushrooms to be harvestable. Link to comment Share on other sites More sharing options...
D4rkh0bb1T Posted March 26, 2016 Author Share Posted March 26, 2016 (edited) Hi Mobbstar! I changed a couple of things here and there and now the anim is showing the correct level animation. I put a local function GetStatus and erased the one in the fn function. Added the tag "structure" above setpristine. Changed the amount for 0,1,2,3. I believe that's all. I can't understand why it works. Indeed, the tuning amount was not correct. Is there a way I can get something like : {amount = 1, idle = mush1, true} - product = ("red_cap", 1) {amount = 2, idle = mush2, true} - product = ("red_cap", 1), ("green_cap" 1), {amount = 3, idle = mush3, true} - product = ("red_cap", 1), ("green_cap", 1), ("blue_cap"), 1) This way, I could harvest different type of mushroom from the farm. Now I can only harvest one : the red_cap. Tried to add harvestable:SetUp lines with the two other mushrooms, then the game only picked the blue_cap. EDIT 1 : I believe the solution lies within the harvestable component and the SetUp function. I just dont know how. EDIT 2 : SOLVED Edited March 27, 2016 by D4rkh0bb1T 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