ammmm Posted May 30, 2022 Share Posted May 30, 2022 first i use AddClassPostConstruct to work but i don't know which one func is i need it. i targeted the AllRecipes variable in script/recipe.lua AddComponentPostInit("recipe", function(self) if self.inst.IsPrimitiveFellow then local ass = self.AllRecipes for i, v in ipairs(GLOBAL.CRAFTING_FILTERS.ARMOUR.recipes) do ass[v].level = GLOBAL.TECH.NONE end return ass end end) and got err maybe i useing wrong way to use all time so how can i to fix it? Link to comment Share on other sites More sharing options...
Ziro2k Posted May 30, 2022 Share Posted May 30, 2022 A few issues: There is no "recipe" component, so AddComponentPostInit can't be used here. AllRecipes is a global table, not a member of the recipe class. It is shared across all characters between the server and client, so you can't make edits to the table for only a single character like this. The easiest way to accomplish what you're trying to do here would be to create new recipes for armor that have a tech level of none, and then add the builder tag specific to your character so only they can craft these new recipes. for recipe_name, recipe in pairs(AllRecipes) do if CRAFTING_FILTERS.ARMOUR.default_sort_values[recipe_name] ~= nil then local recipe_copy = deepcopy(recipe) local name = "primitivefellow_"..recipe_name recipe_copy.name = name recipe_copy.builder_tag = "your character tag here" recipe_copy.level = TECH.NONE recipe_copy:SetModRPCID() AllRecipes[name] = recipe_copy end end Link to comment Share on other sites More sharing options...
ammmm Posted May 31, 2022 Author Share Posted May 31, 2022 3 hours ago, Ziro2k said: 幾個問題: 沒有“recipe”組件,所以這裡不能使用 AddComponentPostInit。 AllRecipes 是一個全局表,不是配方類的成員。它在服務器和客戶端之間的所有字符之間共享,因此您不能像這樣僅針對單個字符對錶進行編輯。 完成您在此處嘗試執行的操作的最簡單方法是創建技術級別為零的新盔甲配方,然後添加特定於您的角色的構建器標籤,這樣只有他們才能製作這些新配方。 cool i did it, but i found another problem it's other player's arrmor recipe will dispear! Link to comment Share on other sites More sharing options...
Ziro2k Posted May 31, 2022 Share Posted May 31, 2022 (edited) I refined it some more, this should work better. You need to add these recipes back to the armor filter, and you'll also need to check for a builder tag first before copying. for recipe_name, recipe in pairs(AllRecipes) do if recipe.builder_tag == nil and CRAFTING_FILTERS.ARMOUR.default_sort_values[recipe_name] ~= nil then local recipe_copy = deepcopy(recipe) local name = "primitivefellow_"..recipe_name recipe_copy.name = name recipe_copy.builder_tag = "builder tag" recipe_copy.level = TECH.NONE recipe_copy:SetModRPCID() AllRecipes[name] = recipe_copy AddRecipeToFilter(name, "ARMOUR") end end This shouldn't affect anyone but the characters with this builder tag. If it does then something is wrong. Edited May 31, 2022 by Ziro2k Link to comment Share on other sites More sharing options...
ammmm Posted May 31, 2022 Author Share Posted May 31, 2022 (edited) 26 minutes ago, Ziro2k said: 我對其進行了更多改進,這應該會更好。您需要將這些配方添加回盔甲過濾器,並且您還需要在復制之前先檢查構建器標籤。 i want check something in this code. Is add on modmain.lua or character.lua? you say "You need to add these recipes back to the armor filter" which means i need to go recipe_filter.lua find the armour tab and add "primitivefellow_" + itemname? cause i got the variable 'AddRecipeToFilter' is not declared LUA ERROR Edited May 31, 2022 by ammmm Link to comment Share on other sites More sharing options...
Ziro2k Posted May 31, 2022 Share Posted May 31, 2022 (edited) 26 minutes ago, ammmm said: i want check something in this code. Is add on modmain.lua or character.lua? This goes in modmain.lua 26 minutes ago, ammmm said: you say "You need to add these recipes back to the armor filter" which means i need to go recipe_filter.lua find the armour tab and add "primitivefellow_" + itemname? No, you just need to call AddRecipeToFilter(name, "ARMOUR") like I did in my post above. 26 minutes ago, ammmm said: cause i got the variable 'AddRecipeToFilter' is not declared LUA ERROR Some of these variables/functions need GLOBAL. prepended to them because they are not included in the mod environment. GLOBAL.AllRecipes, GLOBAL.CRAFTING_FILTERS, GLOBAL.AddRecipeToFilter, GLOBAL.TECH.NONE, GLOBAL.deepcopy If it says a global variable isn't declared, you likely just need to prepend a GLOBAL. to it. Edited May 31, 2022 by Ziro2k Link to comment Share on other sites More sharing options...
ammmm Posted May 31, 2022 Author Share Posted May 31, 2022 (edited) 43 minutes ago, Ziro2k said: Some of these variables/functions need GLOBAL. prepended to them because they are not included in the mod environment. GLOBAL.AllRecipes, GLOBAL.CRAFTING_FILTERS, GLOBAL.AddRecipeToFilter, GLOBAL.TECH.NONE, GLOBAL.deepcopy If it says a global variable isn't declared, you likely just need to prepend a GLOBAL. to it. but i can't use AddRecipeToFilter Where you find this? I want to see how exactly work it is, but not see in dst script file if it need GLOBAL variable. Then should be found in script file...? Edited May 31, 2022 by ammmm Link to comment Share on other sites More sharing options...
Ziro2k Posted May 31, 2022 Share Posted May 31, 2022 4 hours ago, ammmm said: but i can't use AddRecipeToFilter Where you find this? I want to see how exactly work it is, but not see in dst script file if it need GLOBAL variable. Then should be found in script file...? My mistake, AddRecipeToFilter is in the mod environment, so you call it without using GLOBAL. The function is in modutil.lua, you can see how it works by looking there. Link to comment Share on other sites More sharing options...
ammmm Posted June 1, 2022 Author Share Posted June 1, 2022 7 hours ago, Ziro2k said: My mistake, AddRecipeToFilter is in the mod environment, so you call it without using GLOBAL. The function is in modutil.lua, you can see how it works by looking there. for recipe_name, recipe in pairs( GLOBAL.AllRecipes) do if recipe.builder_tag == nil and GLOBAL.CRAFTING_FILTERS.ARMOUR.default_sort_values[recipe_name] ~= nil then local recipe_copy = GLOBAL.deepcopy(recipe) local name = recipe_name recipe_copy.name = name recipe_copy.builder_tag = "mayushii" recipe_copy.level = GLOBAL.TECH.NONE recipe_copy:SetModRPCID() GLOBAL.AllRecipes[name] = recipe_copy GLOBAL.InsertPostInitFunctions(AddRecipeFilter(name, "ARMOUR")) end end i'm try to call this func but seems donesn't work well how to call a loacal func in modmain.lua i want to see your all this code's file, very sure definitely not like this Link to comment Share on other sites More sharing options...
ammmm Posted June 10, 2022 Author Share Posted June 10, 2022 i did it! very easy and intuitive local structures = { "your wants item name" } for i=1, #structures do inst.components.builder:UnlockRecipe(structures[i]) end 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