Drawing basics

The Lua scripting language allows you to give your plugin more advanced features.
User avatar
Bearbear76
Inhabitant of a Multiverse
Reactions:
Posts: 5701
Joined: 10 Feb 2017, 12:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: Drawing basics

Post by Bearbear76 » 25 Jun 2020, 08:48

KINGTUT10101 wrote: 25 Jun 2020, 06:35 The building info box isn't what I need, unfortunately. Thanks for the help though.
You probably use fixed values such as

Code: Select all

Drawing.drawText("Hello Lua!", 20, 70)
This won't accommodate for resolution changes. Now, first we have to understand that x = 0 is the left edge of the screen and y = 0 is the top edge making x, y = 0, 0 the top left corner of your phone. So the x value is relative to the left edge and the y value is relative to the top edge so if we change the resolution the text would go up. Let's say you had a screen resolution of 500x500px and put your y value as 100 now, you increase the resolution to 1000x1000px your text would still be 100px from the top edge but now there's 500 more pixels below making it look like it shifted upwards. So what's the solution?
To make the y value relative to the bottom of the screen!

Lua:

Code: Select all

local _, height = Drawing.getSize()
Drawing.drawText("Hello Lua!", 20, height - 70)
This will make the text always 70px above the bottom edge so resolution changes wont affect the text anymore. Think of it as TheoTown pulling the bottom screen downwards and you attached a helium balloon to the bottom of the screen. No matter how hard you pull the screen up or down the balloon will always float to the length of the string (in this case 70).

I hope this helped!

:jb: bear out!
Just my opinion
retired
User avatar
KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2208
Joined: 07 Jul 2016, 20:50
Location: 'Merica
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Drawing basics

Post by KINGTUT10101 » 25 Jun 2020, 14:55

Thank you guys for the help. I have one last question (for now). How can I make this new element I'm drawing in the screen disappear when "Hide UI" mode is used?
User avatar
Lakan Haraya
Metropolitan
Reactions:
Posts: 129
Joined: 28 Mar 2019, 07:34
Location: Philippines
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Drawing basics

Post by Lakan Haraya » 06 Sep 2020, 02:23

KINGTUT10101 wrote: 25 Jun 2020, 14:55 ... How can I make this new element I'm drawing in the screen disappear when "Hide UI" mode is used?
I'm following this question.
"ᜀᜃᜓ ᜀᜅ᜔ ᜁᜌᜓᜅ᜔ ᜑᜇᜌ"
CEO of Haráya Motors

“TheoTown Philippines Council”
“Kapulungan Ng Mga Nagkakaisang Lungsod”
User avatar
ian`
Metropolitan
Reactions:
Posts: 117
Joined: 04 Apr 2020, 15:36
Location: 日本
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Drawing basics

Post by ian` » 06 Sep 2020, 03:43

Code: Select all    Reset

if not TheoTown.SETTINGS.hideUI then Drawing.drawText('Hello World', 50, 50) end
Lua editor
Run
:bc
User avatar
Lakan Haraya
Metropolitan
Reactions:
Posts: 129
Joined: 28 Mar 2019, 07:34
Location: Philippines
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Drawing basics

Post by Lakan Haraya » 06 Sep 2020, 15:29

Awesome!!! It works...
"ᜀᜃᜓ ᜀᜅ᜔ ᜁᜌᜓᜅ᜔ ᜑᜇᜌ"
CEO of Haráya Motors

“TheoTown Philippines Council”
“Kapulungan Ng Mga Nagkakaisang Lungsod”
User avatar
anakpelajarindo
Settler
Reactions:
Posts: 4
Joined: 31 Dec 2020, 04:28

Re: Drawing basics

Post by anakpelajarindo » 30 Nov 2021, 16:24

But how to align the drawing to the left, right, center, top, and the bottom of the screen? (e.g. targeting circle on the rocket launcher shooting mode)
hi, please read carefully, because it's important


ɴʟᴘ
🇮🇩
N𝔞𝔱𝔦𝔬𝔫𝔞𝔩𝔦𝔰𝔱 L𝔲𝔞 P𝔯𝔬𝔤𝔯𝔞𝔪𝔪𝔢𝔯