• Print

Author Topic: Just help me with a tutorial or examples.  (Read 4823 times)

0 Members and 1 Guest are viewing this topic.

Offline DankNessProvides

  • Newbie
  • *
  • Posts: 26
  • Karma: -3
Just help me with a tutorial or examples.
« on: October 12, 2016, 03:36:55 pm »
I am not really understanding the drawPoly function with the limited description on the wiki, all I am looking for is someone to give me different shaped examples such as a polygon and maybe a trapezium as they are the shapes I want to use for making a HUD. I don't know if trying to use them in the HUD may be the issue I am having but I really just want examples I want to learn from it or just have a great tutorial that will be clear and allow me to make any shape needed. I am not looking for anyone to check code, just asking for someone to give me examples that work or just a clear tutorial.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Just help me with a tutorial or examples.
« Reply #1 on: October 13, 2016, 09:32:32 am »
What exactly are you struggling to understand? surface.DrawPoly just takes a table in the following format:

Code: Lua
  1. {
  2.   { x = number, y = number },
  3.   { x = number, y = number },
  4.   { x = number, y = number }
  5.   ...
  6. }

Each table within the outer table contains a coordinate pair which dictates where the vertex is drawn. surface.DrawPoly just connects the dots between these points (in order) and then fills in the area contained within the lines.

You can use this Khan Academy exercise about polygons on Cartesian coordinate planes to see how different shapes correspond to coordinates.

Here's a trapezoid:



As you can see, the coordinates are at ( -4, 2 ), ( -6, -2 ), ( 6, 2 ), ( 4, 2 ).

If you wanted to do this in Garry's Mod, the table you would pass to DrawPoly would look something like this:

Code: Lua
  1. {
  2.   { x = 300, y = 500 },
  3.   { x = 100, y = 100 },
  4.   { x = 900, y = 100 },
  5.   { x = 700, y = 500 }
  6. }

(I made this trapezoid a bit thinner so it will fit more screen sizes)

Let me know if this didn't make sense to you or if there's something else you're wondering about.
« Last Edit: October 13, 2016, 09:36:39 am by roastchicken »
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

  • Print