Page 1 of 15

[MOD 0.12.x] Autofill

Posted: Fri Nov 01, 2013 2:09 pm
by rk84
Autofill inserts fuel (like coal) to entities (like car) or ammo to turret, when player builds them. (only if player has required items inside main inventory). More details in below.

Download(s)
Tank example.
Tank example.
autofill1.jpg (90.64 KiB) Viewed 96844 times
Mod's default settings:
  • Items used by mod:
    • All itemprototypes with fuelvalue (is sorted from high to low)
    • Bullets: {"piercing-bullet-magazine", "basic-bullet-magazine"}
    • Shells: {"cannon-shell"}
  • car, dielsel-locomotive and tank are loaded with fuel with highest fuelvalue. (+ tank includes ammos too)
  • Burners group: Burner mining drills, Stone furnaces, Steel furnaces, Burner inserters and Boilers work same as vehicles, but all fuel is divided to all "burners" that are in quickbar and hand.
  • Turrets group: Gun turrets are loaded with ammos (First in array first in use). Ammo is divided to all turrets in quickbar and hand.
Mod's interface calls:

Code: Select all

remote.call("af", "insertset", username, entityname, settable)
remote.call("af", "toggleUsage", username)
remote.call("af", "resetUser", "default" or "lite", username)
remote.call("af", "resetMod", ["lite"])
remote.call("af", "getDefaultSets")
remote.call("af", "setDefaultSets", table)
Example of making own autofill set:

Code: Select all

remote.call("af", "insertset", "", "car", {{"coal","raw-wood"}, "basic-bullet-magazine"}) -- Creates personal setting for car.
remote.call("af", "insertset", "", "car", 0) -- insert nothing to car. (ignores default setting)
remote.call("af", "insertset", "", "car", nil) -- reset to default setting
Priority 1 is default and uses coal first. (if priority = 2 then it uses last in array and if it is 3 then item with highest itemcount is used)
Additional keys
  • group: it will divide items between all buildable items that belong to group and are in your quickbar.
  • slots: see control.lua how tank is set up.
Autofill in Github

Re: [MOD 0.7.5] Autofill

Posted: Fri Nov 01, 2013 4:03 pm
by Nirahiel
Awesome :D

Re: [MOD 0.7.5] Autofill

Posted: Fri Nov 01, 2013 6:13 pm
by FreeER
Nirahiel wrote:Awesome :D
I agree, with two comments
First: Why not create a more flexible autoLoad function instead of having one for the car and one for the turret? I suppose it really only matters if you/someone wanted to expand this later (furnaces, other car prototypes, etc.)
Second: what about alternative fuels (wood, coal coke, etc.)? :D

Anyways, thanks for an awesome mod that is truly useful :D

Re: [MOD 0.7.5] Autofill

Posted: Fri Nov 01, 2013 10:48 pm
by rk84
FreeER wrote:
Nirahiel wrote:Awesome :D
I agree, with two comments
First: Why not create a more flexible autoLoad function instead of having one for the car and one for the turret? I suppose it really only matters if you/someone wanted to expand this later (furnaces, other car prototypes, etc.)
Second: what about alternative fuels (wood, coal coke, etc.)? :D

Anyways, thanks for an awesome mod that is truly useful :D
Good points. I guess its partly due mindless copy/paste. Turret loading separated from another of my mod.

I will expand the fuel loading to all car types and more fuel types. But what fuel should have higher priority? One with highest item count?

Re: [MOD 0.7.5] Autofill

Posted: Fri Nov 01, 2013 11:19 pm
by FreeER
rk84 wrote:Good points. I guess its partly due mindless copy/paste. Turret loading separated from another of my mod.
lol It's a bad habit (that almost everyone has, including me :))
I will expand the fuel loading to all car types and more fuel types. But what fuel should have higher priority? One with highest item count?
There are only two logical ways to prioritize most things, quantity and quality (fuel/damage/health value). I do not believe there is currently a way to tell what an item's fuel value is with lua, I tried game.itemprototypes but it only seems to have name/type. which only leaves highest item count, which unfortunately means you can't use it in onload to generate a table of all the bullets either (ammo maybe, but only bullet category works with a turret). Even when it is possible (I'm sure it will be eventually) it seems more logical to me to use the most available, though you could perhaps add another line to the interface so it is possible to change it.

edit: is it possible to send a table from data.lua to control.lua? Would give access to every prototype field if possible

Re: [MOD 0.7.5] Autofill

Posted: Sat Nov 02, 2013 1:00 pm
by rk84
FreeER wrote:There are only two logical ways to prioritize most things, quantity and quality (fuel/damage/health value). I do not believe there is currently a way to tell what an item's fuel value is with lua, I tried game.itemprototypes but it only seems to have name/type. which only leaves highest item count, which unfortunately means you can't use it in onload to generate a table of all the bullets either (ammo maybe, but only bullet category works with a turret). Even when it is possible (I'm sure it will be eventually) it seems more logical to me to use the most available, though you could perhaps add another line to the interface so it is possible to change it.
I having some difficulties on making flexible system. I might be over thinking this. Current status: I still have 2 functions. now autofuel and autofill. Plan is to have only one or both executed depenting on what kind item sets are stored in fillable and fuelable tables. Tables use entity name or type as key and stored values have arrays of item names (or could use item stacks). Autofill could try to insert everything given in item set. Autofuel inserts fuel of one type (max one stack or fill all slots?) depending on highest itemcount or order of array. I will extend the interface to control most of this if not all.

Example of default table values

Code: Select all

--Default fueling
local fuelable =	{
						car = {"coal","raw-wood","wood"},
						locomotive = {"coal"}
						}
local fuel_priority = "itemcount" --itemcount/array. Fuel with highest itemcount or fuel first in array is used first.

--Default filling
local stacksize = 25
local fillable = 	{ --First in array first in use.
						["ammo-turret"]={"piercing-bullet-magazine","basic-bullet-magazine"}
						}
FreeER wrote: edit: is it possible to send a table from data.lua to control.lua? Would give access to every prototype field if possible
As far as I know not from data.lua, but in control.lua I used to insert mods subfolder -path into package.path, define dataloader and then just request data. It might be better to ask/suggest additional prototype properties.

Re: [MOD 0.7.5] Autofill

Posted: Sat Nov 02, 2013 3:43 pm
by FreeER
ok, so what's the problem? lol. Hm, thinking about it you could rewrite the autoLoad function to check the fuelable/fillable tables and then branch with an if statement (which thinking about it is pretty similar to what you had lol, onevent->autoFuel/autoFill). Hm, mainly I'd say when it is possible (or maybe request these), to use something like this, so that it is (likely) fully compatible with any other mods or future vanilla additions without updates, extra script interfaces ect.

Code: Select all

local ammo = {}
local fuel = {}
for _, item pairs(game.itemprototypes) do
  if item.fuel_value then table.insert(fuel, item.name=item.fuel_value) end
  if item.type == "ammo" and item.ammo_type.category=="bullet" then
    table.insert(ammo, {item.name=item.ammo_type.action.action_delivery.target_effects[2].damage.amount)
  end
end
table.sort(fuel)
glob.fuel=fuel --could make it glob.fuel in the first place but...
table.sort(ammo)
fillable["ammo-turret"]=ammo
could have the ammo/fuel tables have sub tables of quality and quantity sorted tables, the quantity would be updated and resorted with the players inv each time autoload is called...then it's just a matter of setting which table to use and inserting ammo.priority[1] or fuel.priority[1]

Hm, when I first saw this I tried writing two functions that were slightly more flexible, more because I needed something to distract me from what I'd been working on than anything else. Here's the modded control I'd made (I'm still using the original to be honest tho). Also, I think the best method would be a combo of the two I made up here, using fuelable and fillable tables to check if the createdentity is one we care about and then passing the entity and fuel/ammo to the autoLoad function which simply checks for items in player inv and then inserts/removes it.

P.S. maybe add burner inserters to the fuelable list :)

Re: [MOD 0.7.5] Autofill

Posted: Sat Nov 02, 2013 8:38 pm
by ficolas
First: Why not create a more flexible autoLoad function instead of having one for the car and one for the turret? I suppose it really only matters if you/someone wanted to expand this later (furnaces, other car prototypes, etc.)
Do it now and dont wait or you will end with arround 500 lines of copypasted code that can be done in... 30 lines? Or so xD
*Cof onplacedentity in f-mod cof*

Re: [MOD 0.7.5] Autofill

Posted: Sun Nov 03, 2013 10:21 am
by slpwnd
Nice mod:) I especially like the different color of flying texts depending on the amount entered.

Re: [MOD 0.7.5] Autofill

Posted: Mon Nov 04, 2013 4:36 pm
by rk84
Uploaded new version.
FreeER wrote:ok, so what's the problem?...
I guess my problem was, still is, different use cases I try to cover with this mod. I hope you try the new code :)
ficolas wrote:Do it now and dont wait or you will end with arround 500 lines of copypasted code that can be done in... 30 lines? Or so xD
*Cof onplacedentity in f-mod cof*
heh I'm too scared to check you code anymore :lol:
kovarex wrote:Add fuel value to item prototype in lua.
Noted.
Cool. This will be most likely used in this mod in future.
slpwnd wrote:Nice mod:) I especially like the different color of flying texts depending on the amount entered.
Thanks :)

Re: [MOD 0.7.5] Autofill

Posted: Wed Nov 06, 2013 10:16 pm
by rk84
After playing with this mod some time. I think choosing item based on item count was not so great as I though. I mostly want to use only coal or coal first.

In late game, you don't notice this mod at all except when you place a car, which is nice. But it led me to think think, should I add some module sets. Like production modules in miners.

Re: [MOD 0.7.5] Autofill

Posted: Fri Jun 27, 2014 9:30 pm
by orion420
I have a friend who swears by gun turrets he will love this mod. Thanks!!!

Re: [MOD 0.11.x] Autofill

Posted: Thu Nov 20, 2014 12:56 pm
by rk84
Updated for Factorio 0.11.3
Added our new friend tank and some improvements for code.

Edit: Mod is auto-activated for each user, but setting are global for all player (assuming this mod works in mp)
Possible todo personal settings.

Re: [MOD 0.11.x] Autofill

Posted: Thu Nov 20, 2014 7:11 pm
by Align
Oh, I hope this functionality gets added official-like to the game, no-one should be without it!

Re: [MOD 0.11.x] Autofill

Posted: Fri Nov 21, 2014 3:17 pm
by SuperSandro2000
I like the idea but when I want to place a train that runs on liquid fuel and I have wood on my inventory I must empty the train after the building -.-.

Re: [MOD 0.11.x] Autofill

Posted: Fri Nov 21, 2014 9:53 pm
by rk84
SuperSandro2000 wrote:I like the idea but when I want to place a train that runs on liquid fuel and I have wood on my inventory I must empty the train after the building -.-.
You mean solid fuel or some custom fuel?

Re: [MOD 0.11.x] Autofill

Posted: Sat Nov 22, 2014 6:10 am
by SuperSandro2000
yes, solid fuel is made out of liquid so liquid fuel^^

Re: [MOD 0.11.x] Autofill

Posted: Sat Nov 22, 2014 10:27 pm
by rk84
You can edit what gets inserted in locomotive. Here is command that should help.

Code: Select all

remote.call("autofill", "insertset", "diesel-locomotive", {slots={3}, {"solid-fuel"}})

Re: [MOD 0.11.x] Autofill

Posted: Sun Nov 23, 2014 6:07 am
by SuperSandro2000
to complicated

Re: [MOD 0.11.x] Autofill

Posted: Sun Nov 23, 2014 5:30 pm
by FishSandwich
kovarex wrote:
Align wrote:Oh, I hope this functionality gets added official-like to the game, no-one should be without it!
This is what I think as well now :)
That awesome moment where a mod is deemed worthy of being implemented into the vanilla game. :D