[0.15] Script for new recipe system

Enhance your gameplay with these tools. This category is also the right place for tools useful for modders.
Mod databases, calculators, cheatsheets, multiplayer, scripts, libs and other useful stuff that is not strictly in-game mods.
Post Reply
Kp0ral
Manual Inserter
Manual Inserter
Posts: 1
Joined: Wed Aug 02, 2017 9:21 am
Contact:

[0.15] Script for new recipe system

Post by Kp0ral »

Hello everyone, i've made this script for personal use ( for a light mod who change unwanted item ).
So i share it for anyone want it, you can use it, edit it or watever you want :

Code: Select all

local SwitchTo = {

	[ "iron-stick" ] = { "iron-plate", 2 },
	[ "iron-gear-wheel" ] = { "iron-plate", 2 },
	[ "wood" ] = { "raw-wood", 1 },
	[ "copper-cable" ] = { "copper-plate", 2 },
	
	[ "heavy-oil" ] = { "crude-oil", 1 },
	[ "light-oil" ] = { "crude-oil", 1 },
	[ "petroleum-gas" ] = { "crude-oil", 1 },
	[ "lubricant" ] = { "crude-oil", 1 }

}

for _, r in pairs( data.raw.recipe ) do
	
	-- Switching to the new recipe system ( normal only ! )
	if r.normal == nil then
	
		r.normal = {}
		r.normal.ingredients = r.ingredients
		r.ingredients = nil
		
	end
	
	if r.result ~= nil then
	
		r.normal.result = r.result
		r.result = nil
	
	end
	
	if r.results ~= nil then
	
		r.normal.results = r.results
		r.results = nil
	
	end
	
	if r.result_count ~= nil then
	
		r.normal.result_count = r.result_count
		r.result_count = nil
	
	end
	
	if r.requester_paste_multiplier ~= nil then
	
		r.normal.requester_paste_multiplier = r.requester_paste_multiplier
		r.requester_paste_multiplier = nil
	
	end
	
	for k, v in pairs( r.normal.ingredients ) do	
		
		-- Using id instead of numeric index
		if v.name == nil then
			
			v.amount = v[ 2 ]
			v.name = v[ 1 ]
			
			v[ 2 ] = nil
			v[ 1 ] = nil
		
		end
		
		-- Cleanup unwanted item ( here you can delete this code, it's only made for my personnal use )
		if SwitchTo[ v.name ] then
		
			v.amount = math.ceil( v.amount / SwitchTo[ v.name ][ 2 ] )
			v.name = SwitchTo[ v.name ][ 1 ]
		
		end
		
		-- Cleaning duplicate entry
		for i = #r.normal.ingredients, 1, -1 do
	
			for k, v in pairs( r.normal.ingredients ) do
			
				if r.normal.ingredients[ k ] ~= nil and r.normal.ingredients[ i ] ~= nil then
				
					if r.normal.ingredients[ i ].name == r.normal.ingredients[ k ].name and k ~= i and
						r.normal.ingredients[ k ].amount ~= nil and r.normal.ingredients[ i ].amount ~= nil then
						
						r.normal.ingredients[ k ].amount = r.normal.ingredients[ k ].amount + r.normal.ingredients[ i ].amount
						r.normal.ingredients[ i ] = nil
						
					end
				end
			end
		end
	end
end
I have no problem for 0.15, but for other version and because i transfer all data to the new recipe system, idk if it work with other version of factorio.
Also i'm not sure why, but using this system unlock some recipes ( plane, transfer belt and a cool weapon xD ).

How work this script, first off i create all needed entry to switch between normal entry to new entries ( normal / expensive ( where isn't use at all here, it work only for normal because i don't need expensive ) then for my mod i switch unwanted item to base item and keep material ratio.

After that, i need to cleanup duplicate keys ... because you know by switching "iron-stick" to "iron-plate" you have in some case :

Code: Select all

{
	{ "iron-plate", 2 },
	{ "iron-plate", 3 }
}
So crafting by hand isn't a problem, but by using assembling machine it wont work because it keep 2 entries rather than one, and inserter don't fill all.
To finish my script also clean all unwanted data key, just to cleanup the code ! It work fast but idk about compatibility with other mod, i think it was better to implement it on your own code if you want use it, but ! for the second time, be careful about compatibility, because this script work on ALL recipe registered.

Hope to help someone with that.

Post Reply

Return to “Tools”