Name: Lua Cominator
Description: Run a lua script in response to wire network. Can be used to query and control most in game objects. Basically command blocks for Factorio
License: MIT
Version: 0.0.1
Release: 2015-08-30
Tested-With-Factorio-Version: 0.12.x
Category: Item
Tags: Logistics, Scripting, Lua
Download-Url: Download v0.0.2
Website: Forum Thread (you are here!)
Long description
Long description
Usage
Using the Lua Combinator requires lua scripting knowledge. A good way to start with this mod is by basing away in the console and editing the examples.
The Lua Combinator will trigger a lua script when a logistics condition is met. It has option to repeat the script, to run it once after the condition changes and it to loop over entities.
This can be used for smart trains, accumulator, gates signals, roboports. logistics networks. Anything ht emod API can touch you can script with a Lua Combinator.
Repeat, will cause your command to run every half second
Post, run-once, will run your script once after the condition turns to false
Loop, will run your script once for every entity around it (in the 9x9 square)
Your script has access to the following variables (subject to change, sorry)
Usage
Using the Lua Combinator requires lua scripting knowledge. A good way to start with this mod is by basing away in the console and editing the examples.
The Lua Combinator will trigger a lua script when a logistics condition is met. It has option to repeat the script, to run it once after the condition changes and it to loop over entities.
This can be used for smart trains, accumulator, gates signals, roboports. logistics networks. Anything ht emod API can touch you can script with a Lua Combinator.
Repeat, will cause your command to run every half second
Post, run-once, will run your script once after the condition turns to false
Loop, will run your script once for every entity around it (in the 9x9 square)
Your script has access to the following variables (subject to change, sorry)
- global: global table shared between all Lua Combinators
condition.value: the condition valu (true if it is met)
condition.changed: has the condition changed?
output: object to write to the wire network
output.entity:, constant-combinator entity
output:clear():, clear output
output:get_count(item): count of item
output:set_count(type,name,count): count of type name. see signals
state: persistent state of Lua Combinator
player: player who built combinator
game: factorio game object (have fun!)
entities: out of loop mode, this is the surrounding entities
entity: in loop mode, this is one of the surrounding entities
Version history
Version history
v0.0.1 initial release.
v0.0.2 fixed bug with zipped version
v0.0.1 initial release.
v0.0.2 fixed bug with zipped version
License
License
The MIT License (MIT)
Copyright (c) 2015 James O'Farrell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
http://opensource.org/licenses/MIT
The MIT License (MIT)
Copyright (c) 2015 James O'Farrell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
http://opensource.org/licenses/MIT
Example Scripts
Example Scripts
Code: Select all
--Wagon Inventory detector (no loop, repeat, post)
if (condition.value) then output:clear() for _,entity in pairs(entities) do if entity.name == "cargo-wagon" then inv = entity.get_inventory(1); for name,count in pairs(inv.get_contents()) do output:set_count("item",name,count); end end end elseif (not condition.value) then output:clear() end
--locomotive-detector (no loop, repeat, post)
if (condition.value) then output:clear() for _,entity in pairs(entities) do if entity.name == "diesel-locomotive" then output:set_count("item","diesel-locomotive",1) end end else output:clear() end
--locomotive pause(loop, repeat, post)
if entity.name == "diesel-locomotive" then entity.train.manual_mode = condition.value end
--rocket launch (loop, repeat)
if (entity.name == "rocket-silo") then player.print("lift off!"); entity.launch_rocket() end
-- rocket detector
output:clear(); for _,entity in pairs(entities) do if entity.name == "rocket-silo" and entity.get_item_count("satellite") > 0 then output:set_count("item","rocket-silo",1) end end
-- rocket banner
if condition.value and not state.banner then state.banner = banner("Ready for launch", output.entity.position, {r=1,g=0,b=0},player,true); player.print("Ready for launch") elseif not condition.value and is_valid(state.banner) then state.banner.destroy(); state.banner = nil; player.print("Life off!") end
--Power detector (no loop, repeat, post)
if (condition.value) then output:clear() for _,entity in pairs(entities) do if entity.type == "accumulator" then output:set_count("virtual","signal-E",math.floor(entity.energy/1000 + 0.5)) end end elseif not condition.value then output:clear() end
--lock the gate - signal (no loop, repeat, post)
output:clear(); for _,entity in pairs(entities) do if entity.name == "rail-signal" and entity.signal_state == 1 then output:set_count("item","rail-signal",1) end end
-- lock the gate- gate (loop, repeat, post)
if entity.name == "gate" then entity.active = not condition.value end
-- floating text (no loop, repeat, post)
if condition.value then banner("Hello World", output.entity.position, {r=0,g=0,b=1},player) end
-- robot usage output
output:clear() if condition.value then if state.net == nil then state.net = output.entity.surface.find_logistic_network_by_position(output.entity.position,player.force.name) end if state.net then output:set_count("item","construction-robot",state.net.available_construction_robots); output:set_count("item","logistic-robot",state.net.available_logistic_robots) end end
-- basic fluid detector
if condition.value and entity.type == "pipe" and entity.fluidbox[1] and entity.fluidbox[1].amount < 1 then if not state.on then player.print("Fluid low"); state.on = true end banner("Fluid: " .. entity.fluidbox[1].amount, output.entity.position, {r=1,g=0,b=0},player) end
--Banner, Power (post)
if condition.value and not state.banner then state.banner = banner("Backup power online", output.entity.position, {r=1,g=0,b=0},player,true); player.print("Backup power online") elseif not condition.value and is_valid(state.banner) then state.banner.destroy(); state.banner = nil end