How to use the LuaRendering

Place to get help with not working mods / modding interface.
Post Reply
ProfoundDisputes
Inserter
Inserter
Posts: 22
Joined: Mon Jun 27, 2016 4:20 pm
Contact:

How to use the LuaRendering

Post by ProfoundDisputes »

I am looking at this LuaRendering api and I have no idea where to start to do anything. All I want to do is draw a rectangle centered around the player. I am essentially trying to replicate the personal roboport range visualization.

If anyone could help me figure this out that would be great! Thank You!

Bilka
Factorio Staff
Factorio Staff
Posts: 3230
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How to use the LuaRendering

Post by Bilka »

Moved to modding help.

Drawing a rectangle is pretty straight forward. https://lua-api.factorio.com/latest/Lua ... _rectangle is used for that, so you can now figure out the properties that you want. Since you say you want it like the radius visualization, you will want it to be filled, drawn on ground and some color. Drawing around the player can be done using the targets + offsets. Here is a console command that does what you want:

Code: Select all

/c local radius = 5
rendering.draw_rectangle({
  surface= game.player.surface,
  filled = true,
  draw_on_ground = true,
  color = {r=0.2,g=0.2,b=0,a=0.5},
  left_top = game.player.character,
  left_top_offset = {-radius,-radius},
  right_bottom = game.player.character,
  right_bottom_offset = {radius,radius}
})
Image
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

ProfoundDisputes
Inserter
Inserter
Posts: 22
Joined: Mon Jun 27, 2016 4:20 pm
Contact:

Re: How to use the LuaRendering

Post by ProfoundDisputes »

Bilka wrote:
Wed Mar 27, 2019 6:30 pm
Moved to modding help.

Drawing a rectangle is pretty straight forward. https://lua-api.factorio.com/latest/Lua ... _rectangle is used for that, so you can now figure out the properties that you want. Since you say you want it like the radius visualization, you will want it to be filled, drawn on ground and some color. Drawing around the player can be done using the targets + offsets. Here is a console command that does what you want:

Code: Select all

/c local radius = 5
rendering.draw_rectangle({
  surface= game.player.surface,
  filled = true,
  draw_on_ground = true,
  color = {r=0.2,g=0.2,b=0,a=0.5},
  left_top = game.player.character,
  left_top_offset = {-radius,-radius},
  right_bottom = game.player.character,
  right_bottom_offset = {radius,radius}
})
Image
Thank You! That worked nicely. I just needed an example to understand how its used.

Post Reply

Return to “Modding help”