Info:
The new electric / hybrid car for your base! If your factory is so big, then you need to use transport for it! This electric car need accumulators during your way. No accumulators - no energy.
It can't stuck with your buildings, but don't use it by your mining outpost.
Name: Electric Ghost Car
Factorio Version: 0.13.x
Latest Release: v0.13.3, 28.06.2016
require("defines")
maxcharge = 5000 --MJ
maxflow = 500 -- kW
maxcapules = 100 -- items
maxconsumption = "500kW" -- 680 hp
maxradius = 25 -- meters / squares
debug = false
script.on_event(defines.events.on_tick, function(event)
addGlob()
for i, player in ipairs(game.players) do
-- if debug then player.print("bPlayerIneCar - " .. player[i].name) end
GUIonoff(player)
if bPlayerIneCar(player) then
ecarCharge(player)
ecarDischarge(player)
end
end
end)
function addGlob()
-- for GUI
if not global.ecarEnergy then global.ecarEnergy = 0 end
if not global.capsules then global.capsules = 0 end
if not global.ecarStations then global.ecarStations = 0 end
end
function GUIonoff(player)
local trigger1 = bPlayerIneCar(player)
local triggertext = trigger1 and "trigger true" or not(trigger1) and "trigger false"
if trigger1 then
if debug then player.print("bPlayerIneCar - " .. triggertext) end
if player.gui.top.ecarGUI == nil then
player.gui.top.add{type="button", name="ecarGUI"}
end
player.gui.top.ecarGUI.caption=string.format("Charging:%i Charge:%i Stations:%i", 100*global.ecarEnergy/maxcharge, global.capsules, global.ecarStations)
else
--player.gui.top.ecarGUI = nil
if debug then player.print("bPlayerIneCar - " .. triggertext) end
--if not player.gui.top.ecarGUI == nil then player.gui.top.ecarGUI = nil end
--if not player.gui.top.ecarGUI == nil then player.gui.top.ecarGUI.destroy() end
--player.gui.top.ecarGUI.destroy()
if not player.gui.top.ecarGUI == nil then player.gui.top.ecarGUI.destroy() end
end
end
function bPlayerIneCar(player)
-- if player.character and player.vehicle and player.vehicle.name == "ghost-e-car" then
if player.character and player.character.vehicle and player.character.vehicle.name == "ghost-e-car" then return true end
return false
end
function ecarCharge(player)
local ecar = player.vehicle -- gets a reference to the ecar
local surface = ecar.surface -- gets the ecar's current surface, normally game.surfaces.nauvis works fine though -- error
local position = ecar.position -- gets the ecar's position
local index2 = 0
local entitiesFound = surface.find_entities_filtered{area = {{position.x-maxradius, position.y-maxradius}, {position.x+maxradius, position.y+maxradius}}, type = "accumulator"}
global.ecarStations = 0
for index, entity in pairs(entitiesFound) do -- loops through all the accumulators
if ecar.get_item_count("energy-capsule") < maxcapules and global.ecarEnergy <= maxcharge and entity.energy > maxflow * 1000 then
index2 = index2 + 1
entity.energy = entity.energy - maxflow * 1000 / index2
global.ecarEnergy = global.ecarEnergy + maxflow / index2
end
global.ecarStations = index
end
end
function ecarDischarge(player)
local ecar = player.vehicle
if global.ecarEnergy > maxcharge-1 then
if ecar.get_item_count("energy-capsule") == nil or ecar.get_item_count("energy-capsule") < maxcapules then
ecar.insert{name = "energy-capsule", count = 1}
global.ecarEnergy = 0
else
end
end
global.capsules = ecar.get_item_count("energy-capsule")
end
Re: [MOD 0.12.x] Ghost Electric Car 0.0.8
Posted: Tue Jun 14, 2016 10:14 pm
by darkfrei
v.0.0.8 - some fixes, tanks and cars can't charging anymore.
Re: [MOD 0.13.x] Electric Ghost Car 0.13.1
Posted: Tue Jun 28, 2016 9:51 pm
by darkfrei
Update to Electric Ghost Car 0.13.3, this code was added/ changed. See Mod changes in 0.13