[Solved] Radar grid position helper

This is the place to request new mods or give ideas about what could be done.
jonatkins
Fast Inserter
Fast Inserter
Posts: 155
Joined: Wed Sep 30, 2015 7:29 pm
Contact:

[Solved] Radar grid position helper

Post 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
debug-0.13-mark.jpg (120.07 KiB) Viewed 10458 times
In 0.14, the chunk coordinates are no longer present.
debug-0.14.jpg
debug-0.14.jpg (55.91 KiB) Viewed 10458 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.
Last edited by jonatkins on Fri Sep 16, 2016 9:34 pm, edited 1 time in total.
giustizieri25
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Jun 24, 2016 10:53 am
Contact:

Re: Radar grid position helper

Post 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.
User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2638
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: Radar grid position helper

Post by steinio »

Well some dashed line like the roboport shows on placement would be sufficient enough.

Greetings steinio
Image

Transport Belt Repair Man

View unread Posts
jonatkins
Fast Inserter
Fast Inserter
Posts: 155
Joined: Wed Sep 30, 2015 7:29 pm
Contact:

Re: Radar grid position helper

Post 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.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Radar grid position helper

Post 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?
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
jonatkins
Fast Inserter
Fast Inserter
Posts: 155
Joined: Wed Sep 30, 2015 7:29 pm
Contact:

Re: Radar grid position helper

Post by jonatkins »

https://mods.factorio.com/mods/jonatkins/RadarGridGuide

Fingers crossed I've done it right...
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Radar grid position helper

Post 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)?
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
jonatkins
Fast Inserter
Fast Inserter
Posts: 155
Joined: Wed Sep 30, 2015 7:29 pm
Contact:

Re: Radar grid position helper

Post 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?
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Radar grid position helper

Post 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.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
jonatkins
Fast Inserter
Fast Inserter
Posts: 155
Joined: Wed Sep 30, 2015 7:29 pm
Contact:

Re: Radar grid position helper

Post 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).
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Radar grid position helper

Post 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.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
jonatkins
Fast Inserter
Fast Inserter
Posts: 155
Joined: Wed Sep 30, 2015 7:29 pm
Contact:

Re: Radar grid position helper

Post 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.
sondo
Manual Inserter
Manual Inserter
Posts: 2
Joined: Thu Oct 06, 2016 2:25 am
Contact:

Re: [Solved] Radar grid position helper

Post 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
jonatkins
Fast Inserter
Fast Inserter
Posts: 155
Joined: Wed Sep 30, 2015 7:29 pm
Contact:

Re: [Solved] Radar grid position helper

Post 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.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5266
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [Solved] Radar grid position helper

Post by Klonan »

jonatkins wrote: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.
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
jonatkins
Fast Inserter
Fast Inserter
Posts: 155
Joined: Wed Sep 30, 2015 7:29 pm
Contact:

Re: [Solved] Radar grid position helper

Post by jonatkins »

Klonan wrote:
jonatkins wrote: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.
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
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.
User avatar
MalcolmCooks
Filter Inserter
Filter Inserter
Posts: 253
Joined: Mon Apr 06, 2015 8:32 pm
Contact:

Re: [Solved] Radar grid position helper

Post 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?
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [Solved] Radar grid position helper

Post 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!
sondo
Manual Inserter
Manual Inserter
Posts: 2
Joined: Thu Oct 06, 2016 2:25 am
Contact:

Re: [Solved] Radar grid position helper

Post 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.
jonatkins
Fast Inserter
Fast Inserter
Posts: 155
Joined: Wed Sep 30, 2015 7:29 pm
Contact:

Re: [Solved] Radar grid position helper

Post 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? :)
Post Reply

Return to “Ideas and Requests For Mods”