Jump to content

[Solved] Recipes availability while running game


Recommended Posts

In recipe.lua I see what arguments I can give to the recipes:
 

Recipe = Class(function(self, name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive, builder_tag, atlas, image, testfn)

But it seems the testfn does nothing ?
I placed "function() return false end" there, but the recipe is still craftable.

So how do I change the availability of a recipe during the game?

edit:
ah I see the testfn is just for placing a structure -.- (so if structure is placeable at a point)...

Ah I think I already found a solution. I just use "builder_tag". So during game I add and remove tags from the players :)
...of course this means alot of different tags, for different recipes... but if there is no other way...

Edited by Serpens
Link to comment
Share on other sites

55 minutes ago, Serpens said:

...of course this means alot of different tags, for different recipes... but if there is no other way...

It's too bad. Any prefab can support only 32 tags. And a player have ~25 tags from the core game. Some mods add 1-2 tags, that's ok (but if too many mods, the game may cause errors).

Link to comment
Share on other sites

17 minutes ago, Maris said:

It's too bad. Any prefab can support only 32 tags. And a player have ~25 tags from the core game. Some mods add 1-2 tags, that's ok (but if too many mods, the game may cause errors).

wtf ?! This sounds horrible ?! Are you sure? I use so much mods, but all of them work. And I'm quite sure they add more than ~7 tags.
I already categorized the recipes, but I can't categorize all of them =/

I want to do the following:
I added a "shop" that is a prototyper. Near it you can exchange dubloons into items (which are added via recipes).

I'm planning a gamemode/modsetting, where no researchlabs exist. Instead you have to find blueprints all over the world.
But I don't want to distribute just random blueprints, it should be used in an adventure, so you will always find the blueprint next which is needed to further progress (eg. a pickaxe to be able to free a path)
But to make sure all players are able to get the recipe, I planned to add the blueprints that were already found, to the shop. So every player can then buy the specific blueprint.

So I would give all players the tags of blueprints that were already gathered (which will be saved in a shop component)
Do you know another good way to implement that?

Edited by Serpens
Link to comment
Share on other sites

I think it's better to make one net var for each player. That numeric variable will mean some kind of level. Then patch builder component so it will use the number for each recipe. And it's better to keep custom table of recipes and its numbers instead of fixing AllRecipes table I guess.

Link to comment
Share on other sites

@MarisI just tried adding the following code to AddPlayerPostInit, and it worked fine:
 

    for i=0,100 do
        inst:AddTag("tag"..i)
    end
    for i=0,100 do
        if inst:HasTag("tag"..i) then
            print("tag"..i)
        else
            print("problem "..i)
        end
    end

But using a function, instead of the Tags, would be much easier though.

Link to comment
Share on other sites

13 minutes ago, Serpens said:

I just tried adding the following code to AddPlayerPostInit, and it worked fine

Enable caves or start dedicated server. It's ok only in local session. Other players (if you are the host) can use only 32 tags.

Try to add 40 tags on the server and check them on client.

Edited by Maris
Link to comment
Share on other sites

30 minutes ago, Maris said:

Enable caves or start dedicated server. It's ok only in local session. Other players (if you are the host) can use only 32 tags.

okay.... you are right, now I get this error when player joins (but the "tag1"... are still printed):
[00:01:14]: [string "scripts/widgets/inventorybar.lua"]:150: attempt to index local 'inventory' (a nil value)

Also with adding 10 tags... adding 2 tags work, so it seems you are really right with 32 tags in total O.ô

But that is really really horrible. Lot's of mods are adding Tags. 32 is definetely too less?! And the biggest thing is, that we get no error message like "too much tags", we get a inventory error?! this makes me really angry... @V2C@ScottHansen

@Marispatching builder component is a good idea. I will add a testfn there, to avoid using tags.

Are there other limitations, e.g for components?

Edited by Serpens
Link to comment
Share on other sites

this is the component mod I use now, :) just if someone is interested.
 

local function recipetestfn(recname,recipe)
    -- ....
end

AddClassPostConstruct("components/builder_replica",  function(self)
	local _CanLearn = self.CanLearn
	self.CanLearn = function(self, recname)
        local recipe = GLOBAL.GetValidRecipe(recname)
        if recipe~=nil and not recipetestfn(recname,recipe) then 
            return false
        else
            return _CanLearn(self, recname) 
        end
	end
end)

if not (GLOBAL.TheNet:GetIsServer() or GLOBAL.TheNet:IsDedicated()) then 
	return
end

AddComponentPostInit("builder", function(self)
	local _CanLearn = self.CanLearn
	self.CanLearn = function(self, recname)
		local recipe = GLOBAL.GetValidRecipe(recname)
        if recipe~=nil and not recipetestfn(recname,recipe) then 
            return false
        else
            return _CanLearn(self, recname) 
        end
	end
end)

 

Edited by Serpens
Link to comment
Share on other sites

4 hours ago, Maris said:

Good solution. :wilson_goodjob:
 

Btw if IsDedicated() is true, GetIsServer() is true too. That means you can use only GetIsServer().

ah thank you very much, I was not sure, cause other mods sometimes used the one and the other.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...