PocketPossum Posted September 7, 2025 Share Posted September 7, 2025 Hi! I have a question. I added an item to my mod that's fun but potentially really abusable, and I was wondering about two things for it. How do I go about adding some kind of mod config option to check if the recipe is allowed to be crafted or not? I was thinking of like, maybe it adds a character tag that says "can_craft_this" and the recipe checks if the character has that tag or not same as it already checks for the character tag, but I'm not sure how to actually get a config setting for it that players can change in the mod menu. I was also wondering, if its possible to make it so a player cannot have more than 1 copy of said item in their inventory? Just disabling the recipe if they have one, or deleting extras or preventing them from picking up a second copy if they stored one. Thank you. Link to comment https://forums.kleientertainment.com/forums/topic/167887-mod-recipe-questions-config-to-disable-recipe-and-also-can-i-limit-item-count-of-recipe/ Share on other sites More sharing options...
FerniFrenito Posted September 7, 2025 Share Posted September 7, 2025 (edited) 2 hours ago, PocketPossum said: Hi! I have a question. I added an item to my mod that's fun but potentially really abusable, and I was wondering about two things for it. How do I go about adding some kind of mod config option to check if the recipe is allowed to be crafted or not? I was thinking of like, maybe it adds a character tag that says "can_craft_this" and the recipe checks if the character has that tag or not same as it already checks for the character tag, but I'm not sure how to actually get a config setting for it that players can change in the mod menu. I was also wondering, if its possible to make it so a player cannot have more than 1 copy of said item in their inventory? Just disabling the recipe if they have one, or deleting extras or preventing them from picking up a second copy if they stored one. Thank you. Yes, you can with this: local recipe_return = GLOBAL.Recipe( -- Your prefab recipe, it doesn't matter if you use Recipe2 "your_prefab", { Ingredient("boards", math.pow(2, 63)), ... ) --[[ canbuild( recipe: the recipe lol owner: the player who craft the object pointOnMap: I think is the position where you craft the object, i really don't know rotation: no idea current_prototyper: no idea ) --]] recipe_return.canbuild = function(recipe, owner, pointOnMap, rotation, current_prototyper) -- Add a "canbuild" function return not owner:HasTag("your_tag") -- If owner has tag, return false and not build the thing end With this the logic part is complete, but in game it looks strange because you can click the crafting button, the player does a crafting animation but won't craft, instead he will say a dialogue. If you need more help with the code I can help you. Edited September 7, 2025 by FerniFrenito Link to comment https://forums.kleientertainment.com/forums/topic/167887-mod-recipe-questions-config-to-disable-recipe-and-also-can-i-limit-item-count-of-recipe/#findComment-1834821 Share on other sites More sharing options...
PocketPossum Posted September 7, 2025 Author Share Posted September 7, 2025 Hi thank you! I do need some help with this. My crafting recipe for it is in modmain.lua, and looks like this. AddCharacterRecipe("destiny_bond", -- name { -- ingredients GLOBAL.Ingredient("nightmarefuel", 2), }, GLOBAL.TECH.MAGIC_TWO, -- tech { -- config product = "destiny_bond", builder_tag = "wobbuffetonly", numtogive = 1, atlas = "images/inventoryimages/destiny_bond.xml", image = "destiny_bond.tex", }, { -- filters "WEAPONS", "MAGIC", } ) Do I need to replace it with what you coded? Or do I just add bits to it, or does it go somewhere else. Link to comment https://forums.kleientertainment.com/forums/topic/167887-mod-recipe-questions-config-to-disable-recipe-and-also-can-i-limit-item-count-of-recipe/#findComment-1834829 Share on other sites More sharing options...
FerniFrenito Posted September 7, 2025 Share Posted September 7, 2025 7 minutes ago, PocketPossum said: Do I need to replace it with what you coded? Or do I just add bits to it, or does it go somewhere else. Instead local recipe_return = GLOBAL.Recipe Use local recipe_return = AddCharacterRecipe(... Link to comment https://forums.kleientertainment.com/forums/topic/167887-mod-recipe-questions-config-to-disable-recipe-and-also-can-i-limit-item-count-of-recipe/#findComment-1834830 Share on other sites More sharing options...
PocketPossum Posted September 7, 2025 Author Share Posted September 7, 2025 Thank you! I got that to work so now if the player has the tag "cant_craft_bond" it prevents them from crafting the item. I was wondering, do you also know how to make the config add or remove that tag from the character? In the config I have some code saying configuration_options = { { name="can_craft_destiny_bond" ,label="Can craft Destiny Bond?" ,options = { {data=1,description="cant_craft_bond"} ,{data=1.1,description="can_craft_bond"} } ,default=1 }, } And in the character's lua file, I have a line of code that says inst:AddTag("wobbuffetonly") Is there a way to have a second inst:AddTag that specifically takes from the config? Or only adds the tag if the config says so. Thank you again btw. Link to comment https://forums.kleientertainment.com/forums/topic/167887-mod-recipe-questions-config-to-disable-recipe-and-also-can-i-limit-item-count-of-recipe/#findComment-1834832 Share on other sites More sharing options...
FerniFrenito Posted September 8, 2025 Share Posted September 8, 2025 25 minutes ago, PocketPossum said: I was wondering, do you also know how to make the config add or remove that tag from the character? Yes, when you add a mod config, you can get the value of "data" selected by the user, the ID of the config is the name. So: local config_can_craft_destiny_bond = GetModConfigData("can_craft_destiny_bond") and, if the user selected cant_craft_bond, the value of config_can_craft_destiny_bond will be 1, if can_craft_bond, then 1.1. The description tag and the hover tag are for the user, you can write there normally because it is information that the user will read. But I think if the world owner turns on that setting, all users in the world will have the same setting, idk. Sometimes it takes me a long time to reply because this doesn't have a notification system. If you need me to reply faster, just let me know. Link to comment https://forums.kleientertainment.com/forums/topic/167887-mod-recipe-questions-config-to-disable-recipe-and-also-can-i-limit-item-count-of-recipe/#findComment-1834837 Share on other sites More sharing options...
PocketPossum Posted September 8, 2025 Author Share Posted September 8, 2025 (edited) 22 minutes ago, FerniFrenito said: Yes, when you add a mod config, you can get the value of "data" selected by the user, the ID of the config is the name. So: local config_can_craft_destiny_bond = GetModConfigData("can_craft_destiny_bond") and, if the user selected cant_craft_bond, the value of config_can_craft_destiny_bond will be 1, if can_craft_bond, then 1.1. The description tag and the hover tag are for the user, you can write there normally because it is information that the user will read. But I think if the world owner turns on that setting, all users in the world will have the same setting, idk. Sometimes it takes me a long time to reply because this doesn't have a notification system. If you need me to reply faster, just let me know. Its okay if you take a bit, its no worries. So I add the local config_can_craft_destiny_bond = GetModConfigData("can_craft_destiny_bond") to the character's lua? What do I do then? Would I try to add something like if config_can_craft_destiny_bond.data = 1 inst:AddTag("cant_craft_bond") end if config_can_craft_destiny_bond.data(1.1) then inst:RemoveTag("cant_craft_bond") end To the onload(inst) function? Or something else. Its my first time working with a mod config option so not 100% how to use the information from it. Edited September 8, 2025 by PocketPossum Link to comment https://forums.kleientertainment.com/forums/topic/167887-mod-recipe-questions-config-to-disable-recipe-and-also-can-i-limit-item-count-of-recipe/#findComment-1834840 Share on other sites More sharing options...
FerniFrenito Posted September 8, 2025 Share Posted September 8, 2025 (edited) 14 minutes ago, PocketPossum said: Its okay if you take a bit, its no worries. So I add the local config_can_craft_destiny_bond = GetModConfigData("can_craft_destiny_bond") to the character's lua? What do I do then? Would I try to add something like if config_can_craft_destiny_bond.data = 1 inst:AddTag("cant_craft_bond") end if config_can_craft_destiny_bond.data(1.1) then inst:RemoveTag("cant_craft_bond") end To the onload(inst) function? Or something else. Its my first time working with a mod config option so not 100% how to use the information from it. If the load corresponds to the load of the element you want to add the label to, yes, but the second "if" is unnecessary, since the game doesn't save mod changes unless you create code for it, so you only need the first "if." If you only need a single value, I recommend using a boolean (true or false) instead of 1 and 1.1. Edited September 8, 2025 by FerniFrenito Link to comment https://forums.kleientertainment.com/forums/topic/167887-mod-recipe-questions-config-to-disable-recipe-and-also-can-i-limit-item-count-of-recipe/#findComment-1834842 Share on other sites More sharing options...
PocketPossum Posted September 8, 2025 Author Share Posted September 8, 2025 (edited) Hi! So I tried using this bit of code here. -- When loading or spawning the character local function onload(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end -- Check config. local config_can_craft_destiny_bond = GetModConfigData("can_craft_destiny_bond") if config_can_craft_destiny_bond.data(1) then inst:AddTag("cant_craft_bond") end end I wound up getting this error. I tried adding ModIndex:GetModActualName(Wobbuffet) but wasn't sure where to add it? And it tells me variable ModIndex is not declared where I put it. Edited September 8, 2025 by PocketPossum Link to comment https://forums.kleientertainment.com/forums/topic/167887-mod-recipe-questions-config-to-disable-recipe-and-also-can-i-limit-item-count-of-recipe/#findComment-1834852 Share on other sites More sharing options...
PocketPossum Posted September 8, 2025 Author Share Posted September 8, 2025 I figured it out! In modmain.lua i added a line of code saying GLOBAL.destiny_config_checker = GetModConfigData("can_craft_destiny_bond") Then in teh character's lua file, wobbuffet.lua, I edited the load function like so. -- When loading or spawning the character local function onload(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end -- Check if you can craft Destiny Bond. if destiny_config_checker == 1 then inst:AddTag("cant_craft_bond") end end So now, if the config option says you can't craft it won't let you craft it, and if it does say you can then you can. Link to comment https://forums.kleientertainment.com/forums/topic/167887-mod-recipe-questions-config-to-disable-recipe-and-also-can-i-limit-item-count-of-recipe/#findComment-1834856 Share on other sites More sharing options...
FerniFrenito Posted September 8, 2025 Share Posted September 8, 2025 9 minutes ago, PocketPossum said: So now, if the config option says you can't craft it won't let you craft it, and if it does say you can then you can. I'm so glad it worked. If you need anything, let me know with a DM or something, although I don't know how that works on this page. Link to comment https://forums.kleientertainment.com/forums/topic/167887-mod-recipe-questions-config-to-disable-recipe-and-also-can-i-limit-item-count-of-recipe/#findComment-1834857 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