Page 1 of 2
[Solved] Radar grid position helper
Posted: Sun Sep 11, 2016 5:27 pm
by jonatkins
Solved: I wrote the mod myself in the end. Find it in the mod portal:
https://mods.factorio.com/mods/jonatkins/RadarGridGuide
Original post:
---------------------------
I like to keep my radars on a strict grid, to ensure complete coverage but avoid overlap.
In 0.13, I'd use the debug mode to show the tile/chunk grid and chunk coordinates.
![debug-0.13-mark.jpg](./download/file.php?id=16836)
- debug-0.13-mark.jpg (120.07 KiB) Viewed 10912 times
In 0.14, the chunk coordinates are no longer present.
![debug-0.14.jpg](./download/file.php?id=16837)
- debug-0.14.jpg (55.91 KiB) Viewed 10912 times
Would it be possible to create a mod that can help with this?
In a basic form, a permanent display of the cursor chunk coordinate would be a great help.
Beyond that, it could include
- Offset, in the range ±3, to the nearest multiple of 7 chunk
- When the player is holding a radar/blueprint with radar, showing the chunk edges on screen
- Support for radar mods with different ranges - detected from the radar in chunk 0,0?
I've never modded the game before, but would like to learn, Some code samples to get me started, or even some pointers on how to do these things, would be a great help. And find out what isn't actually possible to save myself hours of hunting through the docs.
Re: Radar grid position helper
Posted: Sun Sep 11, 2016 6:37 pm
by giustizieri25
I was just about to post a new idea\suggestion right with this exact topic but you preceeded me by minutes.
I would really like also to have that kind of helper in order to optimize the placement of radars.
This could be achieved by creating a new option that can be enabled when activate the debug view, so that you press F5 and the grid gets visualized along with the radars covered area.
Re: Radar grid position helper
Posted: Sun Sep 11, 2016 9:51 pm
by steinio
Well some dashed line like the roboport shows on placement would be sufficient enough.
Greetings steinio
Re: Radar grid position helper
Posted: Mon Sep 12, 2016 3:40 am
by jonatkins
After playing around with the modding API for a bit, and looking at the code of a few other mods for ideas, I've come up with something that's functional.
Basically, I've created a set of decorative crosshair markers that are added at the four corners of the radar chunk position closest to the player position.
If anyone has suggestions for better ways of doing this, let me know. And if you're interested in this mod, I'll look into cleaning it up and publishing to the mod portal.
Re: Radar grid position helper
Posted: Mon Sep 12, 2016 2:11 pm
by aubergine18
@jonatkins we'd ideally need to see it in action before we could make any further suggestions - can you upload a sample mod so we can take a look?
Re: Radar grid position helper
Posted: Mon Sep 12, 2016 3:19 pm
by jonatkins
Re: Radar grid position helper
Posted: Mon Sep 12, 2016 3:40 pm
by aubergine18
It seems to draw the crosses around the starting chunk, but doesn't draw any others after that.
But they are nice design and would help clearly illustrate chunks on map, maybe with a hotkey to toggle them on or off (or maybe only have them appear when player is placing a radar)?
Re: Radar grid position helper
Posted: Mon Sep 12, 2016 3:52 pm
by jonatkins
Did you move 7 chunks away, N/E/S/W? That's the placement grid needed for standard radars.
A hotkey to toggle is on my list: always shown, only when radar/blueprint with radar held, never shown.
Thinking it needs better graphics so you can tell, when zoomed in and only one marker is visible, which chunk is marked. Perhaps corner "L" shaped markers?
Re: Radar grid position helper
Posted: Mon Sep 12, 2016 8:52 pm
by aubergine18
I tried moving quite far away and didn't notice any other markers. Note that I didn't have any radars on the map when I enabled the mod - could that cause it to break? I just started new game with Creative Mode mod so I could quickly spawn radars, etc.
Re: Radar grid position helper
Posted: Mon Sep 12, 2016 9:15 pm
by jonatkins
Creative mode? You mean sandbox with cheats, etc - and no player character?
Just tried this mod in that mode - and it does work. However, the chunk markers are only updated every couple of seconds, and in sandbox mode you can move so fast it's possible to shoot past them before they've updated.
There's no need to build any radars - this version assumes you're first radar is in chunk 0,0 and multiples of 7 chunks from there. Look around coordinates that are multiples of 224 (7 * 32).
Re: Radar grid position helper
Posted: Mon Sep 12, 2016 9:38 pm
by aubergine18
Ah, yes, I see them - I hadn't wandered far enough.
It would definitely be worth adding something that only shows them while player is placing a radar. I think it's player.cursor_stack property? And maybe do similar for when player.selected or player.opened on an existing radar, in which case the position markers would treat that radar as chunk 0,0.
Re: Radar grid position helper
Posted: Fri Sep 16, 2016 9:31 pm
by jonatkins
Mod updated: now considered pretty much 'done'
Changes include
- better visual markers for radar chunks
- hotkey to toggle guide display (Control-G by default)
- reconfigure to reposition guides to match existing radars, or configure for modded radars with larger ranges (hover the mouse cursor over an existing radar, and press Control-G)
Not tested in multiplayer, but it should mostly work. (Each player has their own guides markers, position/visibility settings, etc) One known issue - all guide marks are visible to all players - not much I can do about that with the current modding API.
Re: [Solved] Radar grid position helper
Posted: Mon Nov 28, 2016 8:09 am
by sondo
Hello, just found out messages on the mods portal don't send a notification.
This error:
Code: Select all
RadarGridGuide/control.lua:71: bad argument #1 to 'pairs' (table expected, got nil)
occurs when you make any blueprint and uncheck entities, or make a blueprint consisting only of tiles.
I've fixed it with "if held.get_blueprint_entities() then" after line 70 in control.lua
Thanks for the mod!
Code: Select all
control.lua:60
function isPlayerHoldingRadar(player)
local held = player.cursor_stack
if held and held.valid and held.valid_for_read then
-- is it a radar?
if isRadar(held.name) then
return true
end
-- is it a blueprint containing a radar?
if held.type == "blueprint" and held.is_blueprint_setup() then
local bp = held.get_blueprint_entities()
-- sondos's fix: check for entities here
if held.get_blueprint_entities() then
for _, bpentity in pairs(bp) do
if isRadar(bpentity.name) then
return true
end
end
end
end
end
Re: [Solved] Radar grid position helper
Posted: Mon Nov 28, 2016 8:47 pm
by jonatkins
oops - didn't see your post on the mod portal. Yes, it really should send mod owners notifications...
Anyway, I think I've fixed it. Changes pushed to Github, so you could try that build and confirm?
Releases here:
https://github.com/jonatkins/RadarGridGuide/releases
The changes:
https://github.com/jonatkins/RadarGridG ... ff=unified
Will push to the mod portal soon.
Re: [Solved] Radar grid position helper
Posted: Mon Nov 28, 2016 9:57 pm
by Klonan
You can hook into the 'on_player_cursor_stack_changed' event, which means you won't have to do any on_tick checking
http://lua-api.factorio.com/latest/even ... ck_changed
Re: [Solved] Radar grid position helper
Posted: Mon Nov 28, 2016 10:30 pm
by jonatkins
Things don't only update when the cursor stack changes - it's also based on player position. In 'always' and 'never' modes, only position matters - the cursor stack isn't examined.
What could be useful for this mod is knowing when either:
- the player moves across a chunk boundary
- or even better, the player moves outside of a specified bounding box
But I don't feel it's critical. The on_tick handler only does real work once every couple of seconds (as you can't move that quickly from one radar to the next), and it's all pretty simple when it does update.
Re: [Solved] Radar grid position helper
Posted: Tue Nov 29, 2016 5:04 pm
by MalcolmCooks
Nice! I have altered this to show the exploration grid (29 chunks). But I would like to have both functions - can you add the exploration grid into the mod? Maybe with different colour brackets, or to just be able to switch the mode between showing full coverage and exploration?
Re: [Solved] Radar grid position helper
Posted: Tue Nov 29, 2016 5:26 pm
by Nexela
jonatkins wrote:
What could be useful for this mod is knowing when either:
- the player moves across a chunk boundary
- or even better, the player moves outside of a specified bounding box
0.15 will have a player position event!
Re: [Solved] Radar grid position helper
Posted: Wed Nov 30, 2016 6:19 am
by sondo
Hello, found something else.
Code: Select all
Notice:
Error while running event on_tick (ID 0)
Given item is not a blueprint.
stack traceback:
__RadarGridGuide__/control.lua:69: in function 'isPlayerHoldingRadar'
__RadarGridGuide__/control.lua:138: in function 'updateRadarMarkers'
__RadarGridGuide__/control.lua:238: in function <__RadarGridGuide__/control.lua:219>
Have been able to reproduce this in a new game with only RadarGridGuide (and creative-mode)
Steps to reproduce:
Mode 'when-placing'
Click on blueprint book with no contents
Crashes to menu with gui message above
Not sure why it is dependent upon the mode, but have found that LuaPlayer.cursor_Stack.is_blueprint_setup() doesn't return a boolean for an empty blueprint book, instead giving the error message above.
blueprint book with an empty blueprint returns false
blueprint book with blueprint with entities returns true
empty blueprint book returns "error given item is not a blueprint"
also blueprint book with empty book icon but a blueprint with entities in book returns error, and returns boolean when there is a blueprint in the book icon spot.
Re: [Solved] Radar grid position helper
Posted: Thu Dec 01, 2016 10:37 pm
by jonatkins
sondo wrote:Hello, found something else.
(...)
Steps to reproduce:
Mode 'when-placing'
Click on blueprint book with no contents
Crashes to menu with gui message above
Should be fixed in 0.1.3. Any other ways you can break it?
![Smile :)](./images/smilies/icon_e_smile.gif)