Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Making a formula (https://forums.graalonline.com/forums/showthread.php?t=134266585)

greggiles 06-06-2012 01:42 AM

Making a formula
 
I'm not sure how to write it out, but basically trying to make the 'zoom' value get higher as the player.y gets closer to the NPC's this.y

Here is what I got, and if I were to do full script with all values, it would be very very very very long. So looking for a more efficient way

PHP Code:

function onTimeOut() {
 
setTimer(0.05);

 if (
this.y in |player.y-5player.y|)
 { 
  
this.zoom 5;
  }
 if (
this.y in |player.y-8player.y-5|)
 { 
  
this.zoom 4.5;
  }  
 if (
this.y in |player.y-11player.y-8|)
 { 
  
this.zoom 4;
  }  
 if (
this.y in |player.y-14player.y-11|)
 { 
  
this.zoom 3.5;
  } 
 if (
this.y in |player.y-17player.y-14|)
 { 
  
this.zoom 1;
  }
 if (
this.y in |player.y-20player.y-100|)
 { 
  
this.zoom 0;
  }   
 } 

note: this is for the player being below the NPC

Hezzy002 06-06-2012 01:46 AM

All you need is the distance on one axis. Get the absolute value of the difference between the two coordinates and then multiply it to scale, or use exponents to scale exponentially. Assign that new number to the zoom value.

greggiles 06-06-2012 01:50 AM

Quote:

All you need is the distance on one axis. Get the absolute value of the difference between the two coordinates and then multiply it to scale, or use exponents to scale exponentially. Assign that new number to the zoom value.
Yeah, That sounds very confusing lol

DustyPorViva 06-06-2012 01:51 AM

Quote:

Originally Posted by greggiles (Post 1696517)
Yeah, That sounds very confusing lol

Then maybe you need to start reevaluating your scripting projects?

Skyld 06-06-2012 02:10 AM

Start by calculating the distance between the player and the object. If considering both the X and Y axis:
  • Distance between player X and object X: abs(player.x - this.x)
  • Distance between player Y and object Y: abs(player.y - this.y)
From that you can determine the actual distance between the player and the object (perhaps using the Euclidean distance formula). Once you have some number that represents the distance, you can then calculate your zoom.

(The use of abs in the examples above transforms a possibly negative number into a positive "absolute" number. This is because you might get a negative value depending on if the player is to the left or right or above or below the object X and Y coordinates you specify. Details on abs here.)

greggiles 06-06-2012 03:08 AM

Quote:

Then maybe you need to start reevaluating your scripting projects?
Jokes on you I figured it out ;)

cbk1994 06-06-2012 03:16 AM

Quote:

Originally Posted by greggiles (Post 1696525)
Jokes on you I figured it out ;)

You really showed Dusty. Maybe now that troll will quit spamming the scripting forums with his elitist anti-noob attitude.

DrakilorP2P 06-06-2012 08:32 PM

Quote:

Originally Posted by DustyPorViva (Post 1696518)
Then maybe you need to start reevaluating your scripting projects?

Unfair; Hezzy002's post is very hard to read.

DustyPorViva 06-06-2012 08:38 PM

Quote:

Originally Posted by DrakilorP2P (Post 1696586)
Unfair; Hezzy002's post is very hard to read.

I didn't just base what I said off of this thread. Hell, the very same distance formula was explained just a few threads down just for him:

http://forums.graalonline.com/forums...hp?t=134266527

Hezzy002 06-07-2012 03:49 AM

Quote:

Originally Posted by DrakilorP2P (Post 1696586)
Unfair; Hezzy002's post is very hard to read.

I dunno, the most advanced things in there are references to absolute values and exponents.. Both of which are covered in 7th grade pre-algebra. It's your own fault if you can't comprehend it, provided you went to middle school. Not like we're talking about college level math here.

EDIT: Maybe the phrasing is a little awkward, I'll give you that.


All times are GMT +2. The time now is 06:31 AM.

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