LuaEquipmentGrid reduce battery energy evenly
LuaEquipmentGrid reduce battery energy evenly
I would like to consume some of the power in the player's batteries. The built-in equipment all draws evenly from the batteries. I can't find a way to do that. I am loathe to loop through every LuaEquipment in the grid and reduce the energy one at a time, for both speed and unevenness reasons.
- Ranakastrasz
- Smart Inserter
- Posts: 2179
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: LuaEquipmentGrid reduce battery energy evenly
Consuming energy directly? No vanilla equipment does that, it draws from a consumer type equipment.
That said, I think you can get the total power stored from the grid and then loop through all of the modules to remove the proportional fraction
That said, this would be somewhat useful.
That said, I think you can get the total power stored from the grid and then loop through all of the modules to remove the proportional fraction
That said, this would be somewhat useful.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Re: LuaEquipmentGrid reduce battery energy evenly
That's the behavior I want to mimic.Ranakastrasz wrote:Consuming energy directly? No vanilla equipment does that, it draws from a consumer type equipment.
Yeah, I went with an even lazier option and just removed from the first batteries for now.Ranakastrasz wrote:That said, I think you can get the total power stored from the grid and then loop through all of the modules to remove the proportional fraction
- Ranakastrasz
- Smart Inserter
- Posts: 2179
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: LuaEquipmentGrid reduce battery energy evenly
If you want to mimic that behavior, use a dummy consumer and get power from it alone.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Re: LuaEquipmentGrid reduce battery energy evenly
Do you have an example of a mod with a dummy consumer? For equipment, not entities.
- Ranakastrasz
- Smart Inserter
- Posts: 2179
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: LuaEquipmentGrid reduce battery energy evenly
Well, not directly, but you could use one of several things.
The main issue is that you probably can't make the tooltip show the power consumption.
Laser turret Equipment. Set range to zero, power consumption to *Lots*, cooldown to *Lots*, etc.
Battery Equipment. Set priority to... Uhm, Primary? I think?. Whatever shields and legs use anyway.
Legs. Set speed boost to 0, power consumption to zero. Otherwise it would use energy if you move, or give you +speed.
Discharge Equipment. Actually, given that that requires an action to activate, it might be the best case. Just don't add a trigger item thinggy.
Night vision, might have unwanted behavior, don't use.
Shields probably have unwanted behavior, but I am unsure. You might be able to set capacity to zero, and then still have it display a power consumption amount. That is probably the best choice.
The main issue is that you probably can't make the tooltip show the power consumption.
Laser turret Equipment. Set range to zero, power consumption to *Lots*, cooldown to *Lots*, etc.
Battery Equipment. Set priority to... Uhm, Primary? I think?. Whatever shields and legs use anyway.
Legs. Set speed boost to 0, power consumption to zero. Otherwise it would use energy if you move, or give you +speed.
Discharge Equipment. Actually, given that that requires an action to activate, it might be the best case. Just don't add a trigger item thinggy.
Night vision, might have unwanted behavior, don't use.
Shields probably have unwanted behavior, but I am unsure. You might be able to set capacity to zero, and then still have it display a power consumption amount. That is probably the best choice.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Re: LuaEquipmentGrid reduce battery energy evenly
Nanobots in the scripts/armormods.lua has some examples that might interest you.
Re: LuaEquipmentGrid reduce battery energy evenly
I don't understand how I would trigger any of those entity types to use power when I want them to.
- Ranakastrasz
- Smart Inserter
- Posts: 2179
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: LuaEquipmentGrid reduce battery energy evenly
....
OnTick, get the equipment grid. Loop through till you find equipment of matching type. Check for enough power for that tick. (60 ticks/second).
Remove that much power if it is available, do your effect. Else, do nothing.
OnTick, get the equipment grid. Loop through till you find equipment of matching type. Check for enough power for that tick. (60 ticks/second).
Remove that much power if it is available, do your effect. Else, do nothing.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Re: LuaEquipmentGrid reduce battery energy evenly
But then the equipment would hold energy when it's not being used, like a roboport or a battery. I don't want that. I want it to just consume electricity directly from the batteries, like the laser defense does.
- Ranakastrasz
- Smart Inserter
- Posts: 2179
- Joined: Thu Jun 12, 2014 3:05 am
- Contact:
Re: LuaEquipmentGrid reduce battery energy evenly
The laser defence does not consume energy directly from the batteries, it stores energy until it has enough energy and a target, then discharges it all for a laser blast. It holds enough for like 3 shots, or a single second of firing. As such, just leave the capacity very low.
Even the frikkin Night vision goggles store enough power for like 12 seconds of operation.
Night vision consumes 10 kW, or 10 kJ/seconds, and stores 120 kJ. It fully charges in half a second as well.
The Laser turret consumes 200 kJ per shot, and holds 220 kJ. It charges at a rate of.... Yes.
Apperently it has no throttle on how fast it charges, presumably to support attack speed upgrades.
Even the frikkin Night vision goggles store enough power for like 12 seconds of operation.
Code: Select all
energy_source =
{
type = "electric",
buffer_capacity = "120kJ",
input_flow_limit = "240kW",
usage_priority = "primary-input"
},
energy_input = "10kW",
Code: Select all
energy_source =
{
type = "electric",
usage_priority = "secondary-input",
buffer_capacity = "220kJ"
},
attack_parameters =
{
type = "projectile",
ammo_category = "electric",
cooldown = 20,
damage_modifier = 15,
projectile_center = {0, 0},
projectile_creation_distance = 0.6,
range = 15,
sound = make_laser_sounds(),
ammo_type =
{
type = "projectile",
category = "electric",
energy_consumption = "200kJ",
projectile = "laser",
speed = 1,
action =
{
{
type = "direct",
action_delivery =
{
{
type = "projectile",
projectile = "laser",
starting_speed = 0.28
}
}
}
}
}
},
Apperently it has no throttle on how fast it charges, presumably to support attack speed upgrades.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16