yanecc Posted July 26, 2024 Share Posted July 26, 2024 (edited) I have customized a workstation, and it basically works as expected. However, the icon on the label is too small, and I don't know what to do with it. Additionally, I want a particular prefab to be craftable only once per day. How could I make it? Maybe I should listen to something and change the recipe tag, but I didn't find the right event. Any help would be greatly appreciated! Edited July 26, 2024 by yanecc Link to comment https://forums.kleientertainment.com/forums/topic/158685-help-how-to-make-the-recipe-of-a-prefab-craftable-only-once-per-day/ Share on other sites More sharing options...
yanecc Posted July 26, 2024 Author Share Posted July 26, 2024 (edited) My current code is as following, which will cause panic when a new day comes. AddRecipe2("free_drink", {}, TECH.APPLESTORE, { product = "goatmilk", nounlock = true, builder_tag = "firstorder", no_deconstruction = true }) AddPlayerPostInit(function(inst) inst:ListenForEvent("makerecipe", function(inst, data) if data.recipe.name == "free_drink" then inst:RemoveTag("firstorder") end end) end) local function AddFirstOrderTagToPlayer(inst, player) local day = GLOBAL.TheWorld.state.cycles local key = player.userid .. "_" .. tostring(day) if not inst.TradingRecord[key] then inst.TradingRecord[key] = true player:AddTag("firstorder") end end local function AddFirstOrderTagToAllPlayers(inst) for _, player in ipairs(GLOBAL.AllPlayers) do AddFirstOrderTagToPlayer(inst, player) end end local function OnDayComplete(inst) inst:DoTaskInTime(0, AddFirstOrderTagToAllPlayers(inst)) end local function OnPlayerJoined(inst, player) AddFirstOrderTagToPlayer(inst, player) end AddPrefabPostInit("world", function(inst) local _OnSave = inst.OnSave local function onSave(inst, data, ...) data.TradingRecord = inst.TradingRecord if _OnSave ~= nil then _OnSave(inst, data, ...) end end inst.OnSave = onSave local _OnLoad = inst.OnLoad local function onLoad(inst, data, ...) if data ~= nil then inst.TradingRecord = data.TradingRecord or {} end if _OnLoad ~= nil then return _OnLoad(inst, data, ...) end end inst.OnLoad = onLoad inst:WatchWorldState("cycles", OnDayComplete) inst:ListenForEvent("ms_playerjoined", OnPlayerJoined) AddFirstOrderTagToAllPlayers(inst) end) Edited July 26, 2024 by yanecc Link to comment https://forums.kleientertainment.com/forums/topic/158685-help-how-to-make-the-recipe-of-a-prefab-craftable-only-once-per-day/#findComment-1737852 Share on other sites More sharing options...
yanecc Posted July 30, 2024 Author Share Posted July 30, 2024 Any idea? Link to comment https://forums.kleientertainment.com/forums/topic/158685-help-how-to-make-the-recipe-of-a-prefab-craftable-only-once-per-day/#findComment-1738283 Share on other sites More sharing options...
_zwb Posted July 30, 2024 Share Posted July 30, 2024 你把制作栏的贴图做大点不就行了 Link to comment https://forums.kleientertainment.com/forums/topic/158685-help-how-to-make-the-recipe-of-a-prefab-craftable-only-once-per-day/#findComment-1738303 Share on other sites More sharing options...
yanecc Posted July 30, 2024 Author Share Posted July 30, 2024 48 minutes ago, _zwb said: 你把制作栏的贴图做大点不就行了 我对mod贴图方面不太了解,原图片是64x64的尺寸,我尝试过将图标放大到256x256以后重新打包,替换原图片重新上传以后,无法正确显示放大后的图标,而是被替换成了默认的制作图标。我无法确定是对图标的尺寸有要求,又或者我遗漏了某些步骤。 Link to comment https://forums.kleientertainment.com/forums/topic/158685-help-how-to-make-the-recipe-of-a-prefab-craftable-only-once-per-day/#findComment-1738310 Share on other sites More sharing options...
Harryyw Posted July 31, 2024 Share Posted July 31, 2024 单从你这个报错页面来看,在AddFirstOrderTagToPlayer里,如果世界没有TradingRecord的话要先设置一下呀,不然后边直接访问TradingRecord[key]不就报错了。 1 Link to comment https://forums.kleientertainment.com/forums/topic/158685-help-how-to-make-the-recipe-of-a-prefab-craftable-only-once-per-day/#findComment-1738362 Share on other sites More sharing options...
yanecc Posted July 31, 2024 Author Share Posted July 31, 2024 3 hours ago, Harryyw said: 单从你这个报错页面来看,在AddFirstOrderTagToPlayer里,如果世界没有TradingRecord的话要先设置一下呀,不然后边直接访问TradingRecord[key]不就报错了。 你是对的,我之前只是在inst.OnLoad中初始化变量,但这是不够的,看起来world的inst.OnLoad函数并没有在进入游戏时加载,所以仍需要在prefab主函数中初始化变量。感谢你的提醒! Link to comment https://forums.kleientertainment.com/forums/topic/158685-help-how-to-make-the-recipe-of-a-prefab-craftable-only-once-per-day/#findComment-1738371 Share on other sites More sharing options...
_zwb Posted July 31, 2024 Share Posted July 31, 2024 18 hours ago, yanecc said: 我无法确定是对图标的尺寸有要求,又或者我遗漏了某些步骤。 尺寸对了,就是256*256。可能是哪步漏了 Link to comment https://forums.kleientertainment.com/forums/topic/158685-help-how-to-make-the-recipe-of-a-prefab-craftable-only-once-per-day/#findComment-1738390 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