饥荒联机版

饥荒联机版

腐烂机
nil 2019 年 12 月 27 日 上午 3:13
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...
最后由 nil 编辑于; 2019 年 12 月 27 日 上午 3:14
< >
正在显示第 1 - 5 条,共 5 条留言
nil 2019 年 12 月 27 日 上午 3:17 
我看你的昵称是汉语...如果讲英语嫌麻烦, 可以讲汉语...:steammocking:
最后由 nil 编辑于; 2019 年 12 月 27 日 上午 4:23
辣椒小皇纸  [开发者] 2019 年 12 月 27 日 上午 8:48 
我更新了调用另外一个函数了,不用这么麻烦啦,以后可以兼容任何版本的更新了
你会说中文?
最后由 辣椒小皇纸 编辑于; 2019 年 12 月 27 日 上午 8:49
辣椒小皇纸  [开发者] 2019 年 12 月 27 日 上午 8:51 
By the way, you could contribute your code through Pull Request in Github.
nil 2019 年 12 月 31 日 下午 8:51 
Awl'rite!! I'll du dat. Git Gud!!!!!!!!

哦! 你是用那个类"癞蛤蟆"的腐败能力呀. 这样, 活鱼就得先经历" 死鱼"→"臭鱼 "的过程了. 可按照你原先的" 代码风格 (ge ren qing gan)", 邪恶箱里的活鱼直接变成烂鱼的(直接生成实体(prefab)):steammocking:光明党万岁...
最后由 nil 编辑于; 2019 年 12 月 31 日 下午 9:48
辣椒小皇纸  [开发者] 2019 年 12 月 31 日 下午 10:27 
是的 这样以后更新了新的物品也可以兼容了
< >
正在显示第 1 - 5 条,共 5 条留言
每页显示数: 1530 50