Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-06-2011, 12:53 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Simple Poly Line (to mouse)

Okay this is an easy one, but for some reason I cannot get a line to draw to the players mouse from a given x/y of a npc.. Any suggestions here, i know its top left, top right, bottom right, and bottom left for the order of cords.. or am i wrong here?

PHP Code:
//#CLIENTSIDE
function onMouseDown() {
  
with findImg4000)) {  
    
polygon = {
      
mousexmousey,
      
mousex-(2/16), mousey-(2/16),
      
xy,
      
x-(2/16),y-(2/16)
    };
    
layer 3;
  }

All I am trying to do is make a line draw from the npc to the mouse.. =/

It seems to be twisting, but i cant get the cords working right, grr !!
Reply With Quote
  #2  
Old 01-06-2011, 12:59 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Try swapping x, y with x-(2/16), y - (2/16)

and your explanation sounds misunderstood, it's from point to point to point.
__________________
Quote:
Reply With Quote
  #3  
Old 01-06-2011, 01:03 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
ohh.. guess your right on point-to-point.. hmm
line kinds dissapears at certain angles.. is this normal tho?
Reply With Quote
  #4  
Old 01-06-2011, 01:05 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by scriptless View Post
ohh.. guess your right on point-to-point.. hmm
line kinds dissapears at certain angles.. is this normal tho?
Well you're using layer 0-3, so you'd get better/pixel accuracy if you used layer 4 and up with mousescreenx and mousescreeny.
__________________
Quote:
Reply With Quote
  #5  
Old 01-06-2011, 01:06 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by fowlplay4 View Post
Well you're using layer 0-3, so you'd get better/pixel accuracy if you used layer 4 and up with mousescreenx and mousescreeny.
Was not aware layers had a difference lol.. im trying to make this script plot a position on the level and draw a line to it.. so i can see the NPC's path of movement.. the npc will move along the line and pick another destination but i wanted to see it's path, you know..
Reply With Quote
  #6  
Old 01-06-2011, 01:07 AM
12171217 12171217 is offline
Banned
Join Date: Jan 2009
Posts: 453
12171217 has a spectacular aura about
Quote:
Originally Posted by fowlplay4 View Post
Well you're using layer 0-3, so you'd get better/pixel accuracy if you used layer 4 and up with mousescreenx and mousescreeny.
It's a polygon, not a line with a width/height. Defining the points like that will only result in a proper "thickness" at two angles. The angle has to be compensated for using some trig.
Reply With Quote
  #7  
Old 01-06-2011, 01:08 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
http://forums.graalonline.com/forums...ight=draw+line
__________________
Reply With Quote
  #8  
Old 01-06-2011, 01:09 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
So why does this NOT work?

PHP Code:
//#CLIENTSIDE
function onMouseDown() {
  
this.angle random(0,360); // angle
  
this.distance random(5,7); // distance
  
this.nx sin(this.angle) * this.distance;
  
this.ny cos(this.angle) * this.distance;
  
with findImg4000)) {  
    
polygon = {
      
this.nxthis.ny,
      
this.nx-(2/16), this.ny-(2/16),
      
x-(2/16),y-(2/16),
      
xy
    
};
    
layer 3;
  }
  
chat this.nx SPC this.ny;

The NPC chats the correct cords but does not move to draw poly properly..
Reply With Quote
  #9  
Old 01-06-2011, 01:13 AM
12171217 12171217 is offline
Banned
Join Date: Jan 2009
Posts: 453
12171217 has a spectacular aura about
Also doesn't take into account the direction of the line. Again, needs trig.
Reply With Quote
  #10  
Old 01-06-2011, 01:14 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by 12171217 View Post
Also doesn't take into account the direction of the line. Again, needs trig.
I noticed that.. Downsider is the trig simple or no? I guess the line is not completly important but it's not drawing to the right cords when i used the above script.. the line is just for visual debugging so I guess it doesnt have to be perfect.
Reply With Quote
  #11  
Old 01-06-2011, 01:16 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Nvm, problem solved. I used the DrawLine() custom function and it worked perfectly.. hmm now to redo the other script I had and use this new-found information.

Thanks everyone for the help.
Reply With Quote
  #12  
Old 01-06-2011, 01:31 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Well just using 2 (ox, oy, tx, ty) points works fine as well.
__________________
Quote:
Reply With Quote
  #13  
Old 01-06-2011, 01:31 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by 12171217 View Post
Also doesn't take into account the direction of the line. Again, needs trig.
Sales made one a while back.


Quote:
Originally Posted by salesman View Post
I came across this thread when trying to find out if there was a built in drawLine() function. However, I needed the width of the line to be the same regardless of angle and made this:

PHP Code:
//DrawLine( img_index, start_x, start_y, target_x, target_y, width_in_tiles, red, green, blue, alpha)
public function DrawLineindsxsytxtywidrgbalph ) {
  
temp.ang getangle(tx sxty sy) + (pi/2);
  
temp.wid = ( wid == NULL .1 wid );

  
with findImg(ind) ) {
    
polygon = {
      
sxsy,
      
txty,
      
tx cos(ang)*widty sin(ang)*wid,
      
sx cos(ang)*widsy sin(ang)*wid
    
};
    
red = ( || );
    
green = ( || );
    
blue = ( || );
    
alpha = ( alph <= || alph alph);
    
layer 3;
  }

An example:
PHP Code:
DrawLine(20025254545);
//Draws a black line of width .1 tiles from 25,25 to 45,45 
or if you want to specify color, width and alpha:
PHP Code:
DrawLine(20025254545.3100.5);
//Draws a semi-transparent red line of width .3 tiles from 25,25 to 45,45 
__________________
Reply With Quote
  #14  
Old 01-06-2011, 01:39 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
What's the reasoning for adding pi/2, getangle a fraud?
__________________
Quote:
Reply With Quote
  #15  
Old 01-06-2011, 01:41 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
This doesnt seem to be choosing the random correctly..

PHP Code:
//#CLIENTSIDE
public function DrawLineindsxsytxtywidrgbalph ) { 
  
temp.ang getangle(tx sxty sy) + (pi/2); 
  
temp.wid = ( wid == NULL .1 wid ); 

  
with findImg(ind) ) { 
    
polygon = { 
      
sxsy
      
txty
      
tx cos(ang)*widty sin(ang)*wid
      
sx cos(ang)*widsy sin(ang)*wid 
    
}; 
    
red = ( || ); 
    
green = ( || ); 
    
blue = ( || ); 
    
alpha = ( alph <= || alph alph); 
    
layer 3
  } 
}  

function 
onMouseDown() {
    
this.angle random(this.angle-15,this.angle+15); // angle
    
this.distance random(5,7); // distance
    
this.nx sin(this.angle) * this.distance;
    
this.ny cos(this.angle) * this.distance;
    
DrawLine(2000this.nxthis.nyxy);

The angles are still wrong.. it's supose to pick a random angle within 15 degrees of current angle.. o_O but it's still 360 =/
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:31 PM.


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