Page 1 of 1

[Request] Deevolution script

Posted: Mon Jun 01, 2015 6:54 pm
by Evilness
I would like to request that someone makes a script that would track the number of (mod) furnaces put down and keep track of when each finishes an item. Each time an item would be finished the aliens would de-evolve. I am only requesting the script, because i can make rest of the mod myself. :D

Re: [Request] Deevolution script

Posted: Mon Jun 01, 2015 7:42 pm
by ThaPear
Here, have some untested code that might not even remotely work :D:
(Although even if it doesn't work it'll probably get the idea across)

Code: Select all

game.onload(function() OnLoad() end)
game.oninit(function() OnLoad() end)

game.ontick(function() OnTick() end)

game.onbuiltentity(function(entity) OnBuilt(entity) end)
game.onrobotbuiltentity(function(entity) OnBuilt(entity) end)

game.onentitydied(function(entity) OnRemoved(entity) end)
game.onpreplayermineditem(function(entity) OnRemoved(entity) end)
game.onrobotpremined(function(entity) OnRemoved(entity) end)

function OnLoad()
	if not glob.furnaces then
		glob.furnaces = {}
	end
end

function OnTick()
	-- Check every furnace.
	for _, furnace in pairs(glob.furnaces) do
		local inv = furnace.getoutputinventory()
		if not inv.isempty() then
			-- It's finished crafting.
			game.evolutionfactor = game.evolutionfactor - 1
			-- Remove the crafted item.
			inv.clear()
		end
	end
end

function OnBuilt(entity)
	if entity.name == "pollutionfurnace" then
		-- Store for later use
		glob.furnaces.insert(entity)
	end
end

function OnRemoved(entity)
	if entity.name == "pollutionfurnace" then
		-- Find and remove it from the table.
		for i, v in pairs(glob.furnaces)
			if v.equals(entity) then
				glob.furnaces.remove(i)
				break
			end
		end
	end
end

Re: [Request] Deevolution script

Posted: Mon Jun 01, 2015 8:21 pm
by starholme
You also might want to look at the alien temple mod: https://forums.factorio.com/forum/vie ... =14&t=8863
It does something very similar

Re: [Request] Deevolution script

Posted: Tue Jun 02, 2015 3:46 pm
by Evilness
Yes, i have used that mod and i found it to be overpowered. Even after increasing the power consumption. What i would like to make is a more balanced mod that needs alien artefacts to de-evolve aliens, so that alien evolution will never be decresed by much. I am aiming to balance it so that it will serve more in the sense of slowing alien progression rather then reversing it.

Re: [Request] Deevolution script

Posted: Wed Jun 03, 2015 9:33 pm
by Evilness
I tested the script and it doesnt work. I was able to fix some syntax errors but thats as far as my lua knowledge goes. These lua tables are the wierdest thing to me ( im used to C). Anyone willing to help me out? :D

Re: [Request] Deevolution script

Posted: Thu Jun 04, 2015 8:22 am
by ThaPear
I had misdefined the event triggers, it's been a while since I last modded. (This thread did get me back into it though :D)

Code: Select all

game.onevent(defines.events.ontick, function() OnTick() end)

game.onevent(defines.events.onbuiltentity, function(event) OnBuilt(event.createdentity) end)
game.onevent(defines.events.onrobotbuiltentity, function(event) OnBuilt(event.createdentity) end)

game.onevent(defines.events.onpreplayermineditem, function(event) OnRemoved(event.entity) end)
game.onevent(defines.events.onrobotpremined, function(event) OnRemoved(event.entity) end)
game.onevent(defines.events.onentitydied, function(event) OnRemoved(event.entity) end)

Re: [Request] Deevolution script

Posted: Thu Jun 04, 2015 9:05 pm
by Evilness
I noticed and fixed that. :D There must be something else that is wrong. When the furnace finishes crafting nothing happens. Are you sure the code in ontick function is correct?