Jump to content

Recommended Posts

Hello! I'm making my first mod and I'm trying to change the recipe of an item to reflect it's usefulness of a mod I'm making. This is the last piece of the puzzle before I'm done!

I tried putting this 

Quote

Recipe("item1", {Ingredient("ingredient", 1),Ingredient("ingredient", 1), Ingredient("ingredient", 15)}, RECIPETABS.ANCIENT, TECH.ANCIENT_FOUR, nil, nil, true)

 

Where obviously the item and ingredients are replaced with what I'd like them to be, but it only seems to work in RoG only worlds, but if hamlet and/or shipwrecked are linked then it won't change the recipe. Help? 

53 minutes ago, Ultroman said:

Modinfo Guide

Check that out. I think you may be missing the bools telling the game which DLCs it's compatible with.

I do have those, and all the flags are set to true because if i set any of the DLCs to false it crashes on non-RoG worlds. 

Everything in the mod works perfectly except the recipe change. Is there a different way to make the recipe change in hamlet/sw?

 

Is there a way to have the only only active while you're in RoG but still linked to Hamlet and SW? 

 

Thank you. 

Edited by Scolias

I don't have time to make one of my usual tutorials right now, but this should lead you in the right direction.

Recipe function declarations for each type of game, taken from their recipe.lua files:

-- DS and RoG
Recipe = Class(function(self, name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive)

-- SW
Recipe = Class(function(self, name, ingredients, tab, level, game_type, placer, min_spacing, nounlock, numtogive, aquatic, distance)

-- Hamlet
Recipe = Class(function(self, name, ingredients, tab, level, game_type, placer, min_spacing, nounlock, numtogive, aquatic, distance, decor, flipable, image, wallitem, alt_ingredients)

 

I grabbed this from the game code. I believe it is the best way to check for each kind of DLC. I think there's some difference between how to check for RoG compared to SW and Hamlet, and I don't know why.

if SaveGameIndex:IsModePorkland() then
	-- Do Hamlet code
elseif SaveGameIndex:IsModeShipwrecked() then
	-- Do SW code
elseif IsDLCInstalled(REIGN_OF_GIANTS) then
	-- Do RoG code
else
	-- Do original DS code
end

You can translate those if-statements to bool-variables if you prefer.

Especially for recipes I use this switch in my mods

local function AddModRecipe(_recName, _ingrList, _tab, _techLevel, _recType, _placer, _spacing, _proxyLock, _amount)
	if GLOBAL.CAPY_DLC and GLOBAL.IsDLCEnabled(GLOBAL.CAPY_DLC) or GLOBAL.IsDLCEnabled(GLOBAL.PORKLAND_DLC) then
		return GLOBAL.Recipe(_recName, _ingrList , _tab, _techLevel, _recType, _placer, _spacing, _proxyLock, _amount)
	else
		return GLOBAL.Recipe(_recName, _ingrList , _tab, _techLevel, _placer, _spacing, _proxyLock, _amount)
	end
end

 

If the recipe already exists, this will directly modify the ingredients for said recipe. If the recipe does NOT exist, I would keep using Recipe()

local Ingredient = _G.Ingredient

_G.Recipes["example"].ingredients = {
	Ingredient("item1", 1),
	Ingredient("item2", 5),
	Ingredient("item3", 2)
}

-- A more practical example, let's change the ingredients of a spear to require 2 gold nuggets, 5 logs, and 3 flint.

_G.Recipes["spear"].ingredients = {
	Ingredient("goldnugget", 2),
	Ingredient("log", 5),
	Ingredient("flint", 3)
}

Result:

image.png.3e7b2983f1a639379377a0923ef2136c.png

Hope that helped.

Edited by penguin0616
lua highlight messed up

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
×
  • Create New...