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
  #16  
Old 01-06-2011, 01:42 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
It's in radians, not degrees.

PHP Code:
this.angle random(this.angle-0.261,this.angle+0.261
Google "# degrees to radians" if you need help converting.

You can also use degtorad but it's not recommended to use degrees in scripting anyway.
__________________
Reply With Quote
  #17  
Old 01-06-2011, 01:43 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
edit: been said, but there is functionality in Graal to convert to and from it.

Functions:

degtorad(degrees)
radtodeg(degrees)

I.e:

this.angle = random(this.angle - degtorad(15), this.angle + degtorad(15));
__________________
Quote:
Reply With Quote
  #18  
Old 01-06-2011, 01:50 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
oh, i guess i learn somethign every day XD
Reply With Quote
  #19  
Old 01-06-2011, 02:03 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
What's the reasoning for adding pi/2, getangle a fraud?
You need the points to the left and the right of the line, not in front of it, so you have to subtract 90 degrees, or pi/2 radians.
Reply With Quote
  #20  
Old 01-06-2011, 02:50 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
PHP Code:
function degtorad(temp.d) {
  return 
temp.d*pi/180;
}

function 
radtodeg(temp.r) {
  return 
temp.r*180/pi;

For anyone interested.

A degree is a value between 0 and 360, which we can write as [0,360].
A radian is a value between 0 and 2*pi, which we can write as [0,2*pi].

This is how degtorad would work:
  • Start with [0,360].
  • Divide by 360, and get to [0,1].
  • Multiple by 2pi, and get to [0,2*pi].

(The way I wrote it in the code was divide by 180 then multiple by pi. Same thing.)

radtodeg would just be the opposite.

Also worth noting, 0 points to the right, and positive values rotate counterclockwise.
Reply With Quote
  #21  
Old 01-06-2011, 02:54 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
Someone really needs to go through forum posts, categorize them, and organize them into a tutorial/documentation.
__________________
Quote:
Reply With Quote
  #22  
Old 01-06-2011, 03:20 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
New problem, move() only works first time then stops.. any particular reason behind this?

PHP Code:
function onMouseDown() {
  
this.nx x;
  
this.ny y;
  for ( 
i=0i<3i++ ) {
    
this.angle random(this.angle-0.522,this.angle+0.522); // angle
    
this.distance random(2,5); // distance
    
this.nx2 this.nx sin(this.angle) * this.distance;
    
this.ny2 this.ny cos(this.angle) * this.distance;
    
move(xyx+5y+5);
    
DrawLine(2000+ithis.nxthis.nythis.nx2this.ny2);
    
this.nx += sin(this.angle) * this.distance;
    
this.ny += cos(this.angle) * this.distance;
  }

Reply With Quote
  #23  
Old 01-06-2011, 03:22 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 scriptless View Post
New problem, move() only works first time then stops.. any particular reason behind this?

PHP Code:
function onMouseDown() {
  
this.nx x;
  
this.ny y;
  for ( 
i=0i<3i++ ) {
    
this.angle random(this.angle-0.522,this.angle+0.522); // angle
    
this.distance random(2,5); // distance
    
this.nx2 this.nx sin(this.angle) * this.distance;
    
this.ny2 this.ny cos(this.angle) * this.distance;
    
move(xyx+5y+5);
    
DrawLine(2000+ithis.nxthis.nythis.nx2this.ny2);
    
this.nx += sin(this.angle) * this.distance;
    
this.ny += cos(this.angle) * this.distance;
  }

You can't stack moves on top of eachother like that. Use the option that gives an event when finished (8? check scripthelp) and in the onMovementFinished (if I recall correctly) event call move again.
__________________
Reply With Quote
  #24  
Old 01-06-2011, 03:24 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 something like

PHP Code:
function newmove() {
  if ( 
this.moved == false move(..);
  
this.moved true;
}

function 
onMovementFinished() {
  
this.moved false;
  
newmove();

is what your saying?
Reply With Quote
  #25  
Old 01-06-2011, 03:25 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
move doesn't work like that.

TServerNPC.move(float, float, float, int)
- moves the npc smoothly
- parameters:
delta x,
delta y,
time
options: cache type (0, 1-cache, 2-append) + blockcheck(4) + eventwhendone(8) + applydir(16)

move(dx, dy, time, flags);

I.e:

PHP Code:
//#CLIENTSIDE
function moveTo(txty) {
  
// Delta = Final - Initial
  
temp.dx tx this.x;
  
temp.dy ty this.y;
  
temp.speed 1// Tiles per second
  
temp.time getDistance(this.xthis.ytxty) / temp.speed;
  
move(temp.dxtemp.dytemp.time8); 
}

function 
onMovementFinished() {
  
// Your other code..
}

function 
GetDistance(temp.x1temp.y1temp.x2temp.y2) {
  
temp.toreturn = (temp.x2 temp.x1) ^ + (temp.y2 temp.y1) ^ 2;
  return (
temp.toreturn) ^ .5;

__________________
Quote:
Reply With Quote
  #26  
Old 01-06-2011, 03:28 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
move doesn't work like that.

TServerNPC.move(float, float, float, int)
- moves the npc smoothly
- parameters:
delta x,
delta y,
time
options: cache type (0, 1-cache, 2-append) + blockcheck(4) + eventwhendone(8) + applydir(16)

move(dx, dy, time, flags);

I.e:

PHP Code:
//#CLIENTSIDE
function moveTo(txty) {
  
// Delta = Final - Initial
  
temp.dx tx this.x;
  
temp.dy ty this.y;
  
temp.speed 1// Tiles per second
  
temp.time getDistance(this.xthis.ytxty) / temp.speed;
  
move(temp.dxtemp.dytemp.time8); 
}

function 
onMovementFinished() {
  
// Your other code..
}

function 
GetDistance(temp.x1temp.y1temp.x2temp.y2) {
  
temp.toreturn = (temp.x2 temp.x1) ^ + (temp.y2 temp.y1) ^ 2;
  return (
temp.toreturn) ^ .5;

hmm.. interesting i should have looked up syntax earlier lol.. i thought i was doing it strange.. but still would i do similar to how i posted before because of using move() wrong without the check if movement ended.. ?
Reply With Quote
  #27  
Old 01-06-2011, 03:36 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by scriptless View Post
hmm.. interesting i should have looked up syntax earlier lol.. i thought i was doing it strange.. but still would i do similar to how i posted before because of using move() wrong without the check if movement ended.. ?
Your earlier code looks to me like it'd go on forever.

newmove -> onMovementFinished -> newmove -> onMovementFinished -> newmove -> ...

If you only want to do it a certain amount of times, you could track it in a this variable which you start at say, 3, and then decrease every time the movement is finished.
Reply With Quote
  #28  
Old 01-06-2011, 03:40 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
it looks like i have alot more scripting to do haha .. oh well im bored anyways

yeah it's only suspose to plan 3 moves and then move the paths.. then im gonna need onwall checks .. gah


tho technically it's supose to continiously move.. maybe randomly pause a second or 2.. lol
Reply With Quote
  #29  
Old 01-06-2011, 03:55 AM
12171217 12171217 is offline
Banned
Join Date: Jan 2009
Posts: 453
12171217 has a spectacular aura about
move() is the worst interpolation system EVER created.

When I get my main CPU back, I'll write a REAL interpolation system. I've already written one for Delteria, and it looks lightyears ahead of "move" and reduces server strain a lot. A .25 timeout looks just as good as a .05, and you don't have to deal with using that ****ty move() command where if you change your direction during the middle of the movement, it jumps around. You just do movement like normal, and set a certain attr to a certain value. Easy.
Reply With Quote
  #30  
Old 01-06-2011, 04:01 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by fowlplay4 View Post
What's the reasoning for adding pi/2, getangle a fraud?
because thickness is perpendicular to the angle of the line
__________________
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 06:59 PM.


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