Tesumoto Posted May 30, 2018 Share Posted May 30, 2018 Hello everybody! And again I need your help =) The question is simple, how to prohibit crafting thing for a particular character? I know that can allow crafting for characters by add them with a tag. But I need to allow all but one and not to change the character files. Is it possible to implement it? Link to comment Share on other sites More sharing options...
IronHunter Posted May 30, 2018 Share Posted May 30, 2018 (edited) Its kind of funny because I just built this for my own mod stuff, take note my mod has local variables to reduce the amount of GLOBAL stuff I need to type. You'll have to add those in as you will get errors related to that. Spoiler --In modmain if TUNING.EXCLUDERECIPEMOD ~= true then--prevent multiple instances of this mod running local function _ExcludedRecipe(self, recname) local recipe = GetValidRecipe(recname) if recipe ~= nil then if recipe.exclude_tag ~= nil then for i, v in ipairs(recipe.exclude_tag) do if self.inst:HasTag(v) then return true end end end if recipe.exclude_prefab ~= nil then for i, v in ipairs(recipe.exclude_prefab) do if self.inst.prefab == v then return true end end end end end AddClassPostConstruct("components/builder_replica", function(self) local function IsExcludedRecipe(recname) return (self.inst.components.builder == nil and self.classified ~= nil and _ExcludedRecipe(self, recname)) and true or false end local oldCanLearn = self.CanLearn self.CanLearn = function(self, recipename, ...)return not IsExcludedRecipe(recipename) and oldCanLearn(self, recipename, ...)or false end end) AddComponentPostInit("builder", function(self) local function IsExcludedRecipe(recname) return _ExcludedRecipe(self, recname) and true or false end local oldCanLearn = self.CanLearn self.CanLearn = function(self, recname, ...)return not IsExcludedRecipe(recname) and oldCanLearn(self, recname, ...) or false end end) TUNING.EXCLUDERECIPEMOD = true end To use this simply add this as well to modmain again you'll need to fix the GLOBAL local variables, as I chopped off the GLOBAL parts to save space in my gigantic mod... Spoiler local function excludetags(recname, tags) if AllRecipes[recname]["exclude_tag"] == nil then AllRecipes[recname]["exclude_tag"] = {}end for k, tag in ipairs(tags) do table.insert(AllRecipes[recname]["exclude_tag"], tag)end end local function excludeprefabs(recname, noprefabs) if AllRecipes[recname]["exclude_prefab"] == nil then AllRecipes[recname]["exclude_prefab"] = {}end for k, prefab in ipairs(noprefabs) do table.insert(AllRecipes[recname]["exclude_prefab"], prefab)end end --call this function to add to a recipe --examples excludetags("pickaxe", {"woodcutter", "bearded"})--supports multiple tags excludeprefabs("axe", {"woodie", "wilson"})--supports multiple prefabs I think these are the local variables I have these are placed at the top of the file before the other code local AllRecipes = GLOBAL.AllRecipes local GetValidRecipe = GLOBAL.GetValidRecipe local TUNING = GLOBAL.TUNING Edited May 30, 2018 by IronHunter added local variables Link to comment Share on other sites More sharing options...
Tesumoto Posted May 30, 2018 Author Share Posted May 30, 2018 (edited) 1 hour ago, IronHunter said: Its kind of funny because I just built this for my own mod stuff, take note my mod has local variables to reduce the amount of GLOBAL stuff I need to type. You'll have to add those in as you will get errors related to that. To use this simply add this as well to modmain again you'll need to fix the GLOBAL local variables, as I chopped off the GLOBAL parts to save space in my gigantic mod... I think these are the local variables I have these are placed at the top of the file before the other code Thank you, this is exactly what I was looking for. Could you tell me how to create a random? I need several random values to be selected for the parameter. For example: 240, 300 and 400. Edited May 30, 2018 by Tezumoto Link to comment Share on other sites More sharing options...
IronHunter Posted May 30, 2018 Share Posted May 30, 2018 1 hour ago, Tezumoto said: Thank you, this is exactly what I was looking for. Could you tell me how to create a random? I need several random values to be selected for the parameter. For example: 240, 300 and 400. I really don't understand what you are asking for by random and your example provided. Like math.random() is used usually for creating mostly random numbers when combined with other math functions and equations. lua math library with examples I am just guessing but are you asking for configuration settings? As those are really specific numbers, or did you want to pull random data from a table/array etc? Link to comment Share on other sites More sharing options...
RedHairedHero Posted May 30, 2018 Share Posted May 30, 2018 (edited) math.random(lower number, upper number) This would generate a number from whatever low number and high number you put in. i.e. math.random(1, 400) -- A random number between 1 through 400. *appreciate the link, will personally be using this reference. Edited May 30, 2018 by RedHairedHero Link to comment Share on other sites More sharing options...
Tesumoto Posted May 31, 2018 Author Share Posted May 31, 2018 (edited) 4 hours ago, IronHunter said: I really don't understand what you are asking for by random and your example provided. Like math.random() is used usually for creating mostly random numbers when combined with other math functions and equations. lua math library with examples I am just guessing but are you asking for configuration settings? As those are really specific numbers, or did you want to pull random data from a table/array etc? match.random works with a numbers from "a" to "b". I need to random be only among my chosen numbers. match.random(240 or 300 or 400) - this is an example of what I want to need. Edited May 31, 2018 by Tezumoto Link to comment Share on other sites More sharing options...
IronHunter Posted May 31, 2018 Share Posted May 31, 2018 4 minutes ago, Tezumoto said: match.random works with a numbers from "a" to "b". I need to random be only among my chosen numbers. match.random(240 or 300 or 400) - this is an example of what I want to need. in that case your basically going to have to make a custom function like this: local rng = {240, 300, 400} local function randomindex(t) --Selects a random item from a table local keys = {} for key, value in pairs(t) do keys[#keys+1] = key --Store keys in another table end local index = keys[math.random(1, #keys)] return t[index] end print(randomindex(rng)) 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