Don't Starve Together

Don't Starve Together

Rot Machine
nil 27 Dec, 2019 @ 3:13am
Be carefree. I just copied my code...
:steammocking: Dis iz developed code from dis MOD's "rotbox.lua" file. I think it's could be helpful to yr coding.

function(inst) local con_inst = inst.components.container local num_found = 0 local num_egg = 0 local num_mediumLivingFish = 0 local num_smallLivingFish = 0 local num_rawFish = 0 local num_rawFishSmall = 0 --calculate foods except spoiled foods, rotten eggs, eggs, medium living fish, small living fish, raw fish, small raw fish, spoiled fish and small spoiled fish for k,v in pairs(inst.components.container.slots) do if v.prefab ~= "spoiled_food" and v.prefab ~= "rottenegg" and v.prefab ~= "bird_egg" and not v:HasTag("oceanfish") and v.prefab ~= "fishmeat" and v.prefab ~= "fishmeat_cooked" and v.prefab ~= "fishmeat_small" and v.prefab ~= "fishmeat_small_cooked" then if v.components.stackable then num_found = num_found + v.components.stackable:StackSize() else num_found = num_found + 1 end end end --calculate egg for k,v in pairs(inst.components.container.slots) do if v.prefab == "bird_egg" then num_egg = num_egg + v.components.stackable:StackSize() end end --calculate medium living fish for k,v in pairs(inst.components.container.slots) do if v:HasTag("oceanfish") and ?? then num_mediumLivingFish = num_mediumLivingFish + 1 end end --calculate small living fish for k,v in pairs(inst.components.container.slots) do if v:HasTag("oceanfish") and ?? then num_smallLivingFish = num_smallLivingFish + 1 end end --calculate raw fish for k,v in pairs(inst.components.container.slots) do if v.prefab == "fishmeat" or v.prefab == "fishmeat_cooked" then num_rawFish = num_rawFish + v.components.stackable:StackSize() end end --calculate small raw fish for k,v in pairs(inst.components.container.slots) do if v.prefab=="fishmeat_small" or v.prefab=="fishmeat_small_cooked" then num_rawFishSmall = num_rawFishSmall + v.components.stackable:StackSize() end end -------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------- --turn foods into spoiled foods except spoiled foods, rotten eggs, eggs, medium living fish, small living fish, raw fish, small raw fish, spoiled fish and small spoiled fish if num_found > 0 then for k,v in pairs(inst.components.container.slots) do if v.prefab ~= "spoiled_food" and v.prefab ~= "rottenegg" and v.prefab ~= "bird_egg" and not v:HasTag("oceanfish") and v.prefab ~= "fishmeat" and v.prefab ~= "fishmeat_cooked" and v.prefab ~= "fishmeat_small" and v.prefab ~= "fishmeat_small_cooked" then if v.components.stackable then con_inst:ConsumeByName(v.prefab, v.components.stackable:StackSize()) else con_inst:ConsumeByName(v.prefab, 1) end end end for i = 1, num_found do con_inst:GiveItem(SpawnPrefab("spoiled_food")) end end --turn eggs into rotten eggs if num_egg > 0 then for k,v in pairs(inst.components.container.slots) do if v.prefab == "bird_egg" then con_inst:ConsumeByName(v.prefab, v.components.stackable:StackSize()) end end for i = 1, num_egg do con_inst:GiveItem(SpawnPrefab("rottenegg")) end end --turn medium living fish into spoiled_fish if num_mediumLivingFish > 0 then for k,v in pairs(inst.components.container.slots) do con_inst:ConsumeByName(v.prefab, 1) if v:HasTag("oceanfish") and ?? then end end for i = 1, num_mediumLivingFish do con_inst:GiveItem(SpawnPrefab("spoiled_fish")) end end --turn small living fish into spoiled_fish_small if num_smallLivingFish > 0 then for k,v in pairs(inst.components.container.slots) do if v:HasTag("oceanfish") and ?? then con_inst:ConsumeByName(v.prefab, 1) end end for i = 1, num_smallLivingFish do con_inst:GiveItem(SpawnPrefab("spoiled_fish_small")) end end --turn raw fish into spoiled_fish if num_rawFish > 0 then for k,v in pairs(inst.components.container.slots) do if v.prefab=="fishmeat" or v.prefab=="fishmeat_cooked" then con_inst:ConsumeByName(v.prefab, v.components.stackable:StackSize()) end end for i = 1, num_rawFish do con_inst:GiveItem(SpawnPrefab("spoiled_fish")) end end --turn small raw fish into spoiled_fish_small if num_rawFishSmall > 0 then for k,v in pairs(inst.components.container.slots) do if v.prefab=="fishmeat_small" or v.prefab=="fishmeat_small_cooked" then con_inst:ConsumeByName(v.prefab, v.components.stackable:StackSize()) end end for i = 1, num_rawFishSmall do con_inst:GiveItem(SpawnPrefab("spoiled_fish_small")) end end end

Do u noticed dat " ?? " in da code? Dat's wat I don't know how 2 recognize between "oceanfish_small_{1 to 5}_inv" and "oceanfish_medium_{1 to 5}_inv".
By da way, u can find "oceanfish_small" and "oceanfish_medium" at "scripts/prefabs/oceanfishdef.lua" file.
Sorry for these bothering you if you're on busy days...
Last edited by nil; 27 Dec, 2019 @ 3:14am
< >
Showing 1-5 of 5 comments
nil 27 Dec, 2019 @ 3:17am 
我看你的昵称是汉语...如果讲英语嫌麻烦, 可以讲汉语...:steammocking:
Last edited by nil; 27 Dec, 2019 @ 4:23am
辣椒小皇纸  [developer] 27 Dec, 2019 @ 8:48am 
我更新了调用另外一个函数了,不用这么麻烦啦,以后可以兼容任何版本的更新了
你会说中文?
Last edited by 辣椒小皇纸; 27 Dec, 2019 @ 8:49am
辣椒小皇纸  [developer] 27 Dec, 2019 @ 8:51am 
By the way, you could contribute your code through Pull Request in Github.
nil 31 Dec, 2019 @ 8:51pm 
Awl'rite!! I'll du dat. Git Gud!!!!!!!!

哦! 你是用那个类"癞蛤蟆"的腐败能力呀. 这样, 活鱼就得先经历" 死鱼"→"臭鱼 "的过程了. 可按照你原先的" 代码风格 (ge ren qing gan)", 邪恶箱里的活鱼直接变成烂鱼的(直接生成实体(prefab)):steammocking:光明党万岁...
Last edited by nil; 31 Dec, 2019 @ 9:48pm
辣椒小皇纸  [developer] 31 Dec, 2019 @ 10:27pm 
是的 这样以后更新了新的物品也可以兼容了
< >
Showing 1-5 of 5 comments
Per page: 1530 50