[Request] Deevolution script

This is the place to request new mods or give ideas about what could be done.
Post Reply
Evilness
Inserter
Inserter
Posts: 45
Joined: Wed Apr 15, 2015 3:53 pm
Contact:

[Request] Deevolution script

Post 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

User avatar
ThaPear
Fast Inserter
Fast Inserter
Posts: 226
Joined: Fri May 30, 2014 8:05 am
Contact:

Re: [Request] Deevolution script

Post 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

starholme
Fast Inserter
Fast Inserter
Posts: 201
Joined: Tue Oct 21, 2014 7:25 pm
Contact:

Re: [Request] Deevolution script

Post 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

Evilness
Inserter
Inserter
Posts: 45
Joined: Wed Apr 15, 2015 3:53 pm
Contact:

Re: [Request] Deevolution script

Post 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.

Evilness
Inserter
Inserter
Posts: 45
Joined: Wed Apr 15, 2015 3:53 pm
Contact:

Re: [Request] Deevolution script

Post 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

User avatar
ThaPear
Fast Inserter
Fast Inserter
Posts: 226
Joined: Fri May 30, 2014 8:05 am
Contact:

Re: [Request] Deevolution script

Post 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)

Evilness
Inserter
Inserter
Posts: 45
Joined: Wed Apr 15, 2015 3:53 pm
Contact:

Re: [Request] Deevolution script

Post 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?

Post Reply

Return to “Ideas and Requests For Mods”