Information on mods

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
Ardagan
Fast Inserter
Fast Inserter
Posts: 101
Joined: Sat Dec 21, 2013 11:24 pm
Contact:

Information on mods

Post by Ardagan »

Hi,

I want to write a mod that modifies energy production of solar plants, and some others. The question is, how can I do that?

I though I can use "effect" field of research entity, but I can't get what "type" should I use (or where can I get a list of types).

If anyone can give an example on how to modify solar power station power output using some research, I'd really appreciate that.

If you can give some more general information also, that would be even better.

User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: Information on mods

Post by Dysoch »

Ardagan wrote:Hi,
If anyone can give an example on how to modify solar power station power output using some research, I'd really appreciate that.
this would require a modifier. only a few modifiers exist, and no new ones can be created (yet). so changing power throu research is impossible as of now. (well not entirely, let me explain below)

how it is possible:
by using the control,lua almost anything is possible.

to change the power output you will require more then 1 entity. (2 entities exactly the same, but with different power outputs)
then in the control.lua there will be something like: (carefull, this is untested :P)
(providing you added the solar panel to a table (glob) you can then simply do:

Code: Select all

game.onevent(defines.events.ontick, function(event)
if glob.solar~=nil and game.tick%60==1 and game.player.force.technologies["#NAME OF TECH  that should increase power output#"].enabled then
		for i, solar in pairs(glob.solar) do -- a loop needed for the things below
			if solar.valid then
				local solarposition = solar.position --stores the location of the solar panel
				solar.die() --kills the current solar panel
				game.createentity{name = "the second entity with a higher output", position=solarposition, force=game.forces.player} --replaces it with the higher output solar panel
			break --breaks the loop created above
			elseif not solar.valid then
        table.remove(glob.solar, i) --removes the deleted entity from the table and ends the event forever (or until a new entity is build)
			break
			end
		end
   end 
end)

this does work (at my mod, its a modified spawner changer. but not tested!)

hope this helps :P
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6

Ardagan
Fast Inserter
Fast Inserter
Posts: 101
Joined: Sat Dec 21, 2013 11:24 pm
Contact:

Re: Information on mods

Post by Ardagan »

I knew that you'd be the one to answer Dysoch :)

Then I'll continue asking questions as they appear and, probably, will create wiki page with findings later.

1) Where can I find a list of modifiers? Didn't manage to. (except to grep all different from all entities/etc)

2) Can we just change the power output of some entity? I suppose that there still should be and object of "solar panel" or object of "solar panel" prototype that contains default power output. Thus we should be able to a) change the default power output value (if that's not enough then) b) all new solar-panels will use new default value c) all existing ones are either update value by-default, or we change their output value iterative, or recreate them d) put a handler that changes power output upon building of new solar panel
(some stuff intersects, but the idea is there)

3) is there a way to actually change parameters of existing items?

4) is there a way to dynamically add new entities? => 1) on research complete, we create new research, new item, new recipe and they are accessible. (meaning entity, technology, etc)

5) why do we need break? shouldn't we iterate through all solar panels? :/

User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: Information on mods

Post by Dysoch »

hehehe how did you know that :P?

1) https://forums.factorio.com/wiki/inde ... y-modifier contains all modifiers that exist in the game.

2) not that i know of. the way i descriped is as far as i know the only way.

3) yes, and no. :P no because its impossible to change a item midgame, and yes because it can be done the same way with the solar panels. just check the inventory of a chest or player, and "swap"the item to the same item with different parameters. This requires of course 2 items to be set in the data definitions.

4) technologies cant be hidden in the game. but for recipe, entity and item that is already present. recipes can be unlocked throu research. but adding entities, if you mean adding them directly to the world, that is possible, but with scripting in the control.lua

5) we need to break the loop, because otherwise it keep search for the same entity. the way it works is the following: it searches the table (glob.solar) for the entities placed it the world, and picks one. that one gets replaced with the modified entity and the loop ends. after that, it just picks a new one and starts all over. so it goes throu all panels, but just slower (not very slow, as it happens every second :P)
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6

User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: Information on mods

Post by rk84 »

Dysoch wrote:5) we need to break the loop, because otherwise it keep search for the same entity. the way it works is the following: it searches the table (glob.solar) for the entities placed it the world, and picks one. that one gets replaced with the modified entity and the loop ends. after that, it just picks a new one and starts all over. so it goes throu all panels, but just slower (not very slow, as it happens every second :P)
That loop is obsolete, because everytime first cycle leads to break.

solar.valid => break
not solar.valid => break

There is no third option because.
not nil => true
not false => true

which makes the "elseif not solar.valid then" -line same as using just "else"

Naturally, you can use the "if it works, don't touch it" -philosophy, if you like. :D
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela

Ardagan
Fast Inserter
Fast Inserter
Posts: 101
Joined: Sat Dec 21, 2013 11:24 pm
Contact:

Re: Information on mods

Post by Ardagan »

No No No. After once spending 3 days on code I wrote that worked, but I couldn't understand why, I can't follow "don't touch" philosophy :P

slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: Information on mods

Post by slpwnd »

Ardagan wrote:No No No. After once spending 3 days on code I wrote that worked, but I couldn't understand why, I can't follow "don't touch" philosophy
I decided it's time to stop following "don't touch" philosophy and I am now updating the internals of our webpage. It was using a framework that became obsolete like a year ago :D

Post Reply

Return to “Gameplay Help”