Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Showpoly Explain (https://forums.graalonline.com/forums/showthread.php?t=134264372)

Emera 08-26-2011 11:48 PM

Showpoly Explain
 
I really want to lean towards using images and shapes in my scripts. I thought a good place to start was showpoly. I searched the graal wiki and I didn't find anything that can help me. Maybe you guys can?

fowlplay4 08-26-2011 11:54 PM

There's not a lot to it:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
setTimer(0.05);
}

function 
onTimeout() {
  
showPolygon();
  
setTimer(0.05);
}

// Draw square on mousex and mousey position.
function showPolygon() {
  
// using showpoly
  
showpoly(200, {
     
mousexmousey,
     
mousex 2mousey,
     
mousex 2mousey 2,
     
mousexmousey 2
  
});

  
// Same as doing
  
with (findimg(200)) {
    
polygon = {
     
mousexmousey,
     
mousex 2mousey,
     
mousex 2mousey 2,
     
mousexmousey 2
    
});
  }


The polygon array is just a collection of x, y points listed in order. I.e: {x1, y1, x2, y2, x3, y3, x4, y4};

You can use as many points as you want. I think you need at least 3 sets of x,y points though. Used to be able to draw lines with just two but i believe that changed with V5.

Other Reading:
http://gscript.graal.net/showpoly

Crow 08-27-2011 12:03 AM

Quote:

Originally Posted by fowlplay4 (Post 1665630)
I think you need at least 3 sets of x,y points though. Used to be able to draw lines with just two but i believe that changed with V5.

Quite sure I only got two somewhere..

Emera 08-27-2011 12:05 AM

Takes some fiddling to get the shape you want.

Tricxta 08-27-2011 12:17 AM

Not really,what you do is you plot the outline of the points you want:
Square example:
PHP Code:

temp.square={20,20,40,20,40,40,20,40};
showpoly (300temp.square); 

And this is how I drew it in order of verticies
http://i.imgur.com/wspPW.png

Another example would be drawing a circle:
PHP Code:

temp.radius=4;
for (
temp.i=0;temp.i<(pi*2);temp.i++)temp.circle.add((cos(temp.i)*temp.radius+30),(sin(temp.i)*temp.radius+30));
showpoly (300temp.circle); 

So basically summing up, you draw the outline and the showpoly will fill in the middle. And basically what I've done here in both examples is define an array outside the showpoly statement rather then within it. Hope this helped.

Emera 08-27-2011 01:52 AM

So it is
PHP Code:

showpoly(point1x,point1y,point2x,point2y,point3x,point3y,point4x,point4y); 

Right?

cbk1994 08-27-2011 02:08 AM

Quote:

Originally Posted by Emera (Post 1665646)
So it is
PHP Code:

showpoly(point1x,point1y,point2x,point2y,point3x,point3y,point4x,point4y); 

Right?

No. See the wiki page linked in Jer's post above.

oo_jazz_oo 08-27-2011 03:22 AM

Quote:

Originally Posted by Crow (Post 1665634)
Quite sure I only got two somewhere..

You can use only two. :P
v5 and v6 works just fine using 2 x/y coords.

ff7chocoboknight 08-27-2011 05:13 AM

You need {}. It's an array.

showpoly(index, {x1,y1,x2,y2,...,xn,yn});

That's why Tricxta used temp.square to list the points first.

You forgot the index, too.

gaben 08-27-2011 07:28 AM

Polygons also support RGBA coloring, which is nice I guess.

PHP Code:

green 1;
blue 0;
red 0;
alpha 1

Would output a 'green' polygon. Not sure if you can define/initialize color vars outside of the polygon index though.

Tricxta 08-27-2011 07:52 AM

You should be able too.... just use findimg(index).


All times are GMT +2. The time now is 02:43 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.