Hi, I want to create a radar that works without power grid, however when I place it with 0kw consumption setting the game crashes. I tried making it "solar" with 1w consumption but that didnt work- didn't crash the game tho. Is there a way to modify the energy source to allow it to function without power? I need it to scan only nearby sectors and only for a short duration (implementing charting will be more problematic)
Re: Creating new entity that has 0kw consumption
Posted: Mon Aug 21, 2017 9:36 am
by Adil
Probably no. The game have things like this hardcoded to the very depth of it.
This might have been uncalled for, but the following statement
robertpaulson wrote:(implementing charting will be more problematic)
caught my thought and I've spent fifteen minutes to prove the opposite:
local TIME_TO_LIVE=271--seconds
local TIME_TO_SCAN=30--seconds
local SCAN_RANGE=3--chuncks
local UPD_STEP=60--ticks between updates
local add_radar=function(entity)
table.insert(global.radars,{
entity=entity,
timer=TIME_TO_SCAN,
life=TIME_TO_LIVE,
next_x=-SCAN_RANGE,
next_y=-SCAN_RANGE,
})
end
local update_radars=function(tick)
local rs=global.radars
local t=tick%UPD_STEP
for i=#rs-t,1,-UPD_STEP do
local r=rs[i]
if not r.entity.valid then table.remove(rs,i)
else
r.timer=r.timer-1
r.life=r.life-1
if r.timer<0 then
local e=r.entity
local p,s,f=r.position,r.surface,r.force
local a={x=p.x+r.next_x *32,y=p.y+r.next_y*32,}--if area is less than chunk, whole chunk is charted anyway
f.chart(s,{a,a})
r.timer=TIME_TO_SCAN
r.next_x=r.next_x+1
if r.next_x>SCAN_RANGE then
r.next_x=-SCAN_RANGE
r.next_y=r.next_y+1
if r.next_y>SCAN_RANGE then
r.next_y=-SCAN_RANGE
end
end
end
if r.life<0 then
r.entity.die()
end
end
end
end
script.on_init(function() global.radars={} end)
script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_entity},
function(event)
if event.entity.name=="no-power-radar" then
add_radar(event.entity)
end
end)
script.on_event(defines.events.on_tick,function(event) update_radars(event.tick) end)
Re: Creating new entity that has 0kw consumption
Posted: Mon Aug 21, 2017 5:52 pm
by impetus maximus
Creative mode mod has entities (including radar) that run without power, with power flashing icon still present.
Re: Creating new entity that has 0kw consumption
Posted: Mon Aug 21, 2017 6:14 pm
by robertpaulson
Adil wrote:Probably no. The game have things like this hardcoded to the very depth of it.
This might have been uncalled for, but the following statement
robertpaulson wrote:(implementing charting will be more problematic)
caught my thought and I've spent fifteen minutes to prove the opposite:
local TIME_TO_LIVE=271--seconds
local TIME_TO_SCAN=30--seconds
local SCAN_RANGE=3--chuncks
local UPD_STEP=60--ticks between updates
local add_radar=function(entity)
table.insert(global.radars,{
entity=entity,
timer=TIME_TO_SCAN,
life=TIME_TO_LIVE,
next_x=-SCAN_RANGE,
next_y=-SCAN_RANGE,
})
end
local update_radars=function(tick)
local rs=global.radars
local t=tick%UPD_STEP
for i=#rs-t,1,-UPD_STEP do
local r=rs[i]
if not r.entity.valid then table.remove(rs,i)
else
r.timer=r.timer-1
r.life=r.life-1
if r.timer<0 then
local e=r.entity
local p,s,f=r.position,r.surface,r.force
local a={x=p.x+r.next_x *32,y=p.y+r.next_y*32,}--if area is less than chunk, whole chunk is charted anyway
f.chart(s,{a,a})
r.timer=TIME_TO_SCAN
r.next_x=r.next_x+1
if r.next_x>SCAN_RANGE then
r.next_x=-SCAN_RANGE
r.next_y=r.next_y+1
if r.next_y>SCAN_RANGE then
r.next_y=-SCAN_RANGE
end
end
end
if r.life<0 then
r.entity.die()
end
end
end
end
script.on_init(function() global.radars={} end)
script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_entity},
function(event)
if event.entity.name=="no-power-radar" then
add_radar(event.entity)
end
end)
script.on_event(defines.events.on_tick,function(event) update_radars(event.tick) end)
Well then, maybe I don't belong here or I'm really slow because it took me more than 15 to understand the code lol.... Much thanks for the work! btw, the variable e is never used, why is it there? to verify the r.next is there to simulate the radar scanning sector by sector? that's elegant!
impetus maximus wrote:Creative mode mod has entities (including radar) that run without power, with power flashing icon still present.
those can be removed with render_no_power_icon =false, but if its there the entity doesn't work on 0 power and the work is done by scripts (like the one provided by Adil, above)
Re: Creating new entity that has 0kw consumption
Posted: Mon Aug 21, 2017 6:32 pm
by impetus maximus
ok, i'm not a coder/modder. just trying to help.
Re: Creating new entity that has 0kw consumption
Posted: Mon Aug 21, 2017 7:34 pm
by robertpaulson
impetus maximus wrote:ok, i'm not a coder/modder. just trying to help.
no worries, I will probably take a look at the mod you mentioned. Thank you for info, and sorry if I came on rude, wasn't my intention. cheers.
Re: Creating new entity that has 0kw consumption
Posted: Mon Aug 21, 2017 8:55 pm
by impetus maximus
not at all. cheers
Re: Creating new entity that has 0kw consumption
Posted: Tue Aug 22, 2017 7:34 am
by Adil
robertpaulson wrote:Much thanks for the work! btw, the variable e is never used, why is it there? to verify the r.next is there to simulate the radar scanning sector by sector? that's elegant!
You are welcome. Unused e is a typo, I've intended to read position, force and surface from it, not from r:
local e=r.entity
local p,s,f=e.position,e.surface,e.force
Sorry, about that.
Yes. r.next_x and r.next_y are there to keep track of the next chunk to scan.
Also, I'm lagging behind somewhat. We didn't have the `render_no_power_icon ` field back then. With that, who knows, maybe adding a buffer to the entity's power source (like roboport has) and using scripts to refill it, will suffice.