Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Gmap warp on a custom map script (https://forums.graalonline.com/forums/showthread.php?t=57676)

SSS 02-17-2005 09:04 AM

Gmap warp on a custom map script
 
Hi i have a custom map script on my playerworld and am trying to do the warping for it..
it works but i cant figure out how to get the gmap coords from the screencoords of the map..

The map image is 420x420
The gmap is 15 x 15 levels..
Im not good at math so im having some problems here.. :(
mapxy is the coordinates of the map image on the screen..

How is the math done?
to convert the mousescreen coordinates on the map
to gmap coordinates.. so if i click the bottem right corner i will
warp to the bottem right corner, which is 957x957..

this is a part of the script
NPC Code:

if (mousescreenx in | mapxy[0], mapxy[0] + 420 | &&
mousescreeny in | mapxy[1], mapxy[1] + 420 | ) {
this.mapxy = {mousescreenx-mapxy[0]*6.5,mousescreeny-mapxy[1]*6.5}; //here is where i get the gmap coords from the screencoords
//but the math is wrong

if (keydown2(17, true)) {
triggeraction 0, 0, serverside, -Map, warp, #v(this.mapx),#v(this.mapy);

}
}


Polo 02-17-2005 10:10 AM

Instead of *6.5 you want *(960/420) to scale it to the gmap..

(The map is actually 960 tiles big not 957)

That can be simplified to *(16/7)....

...however i think you have some logical errors... firstly... mapxy[] is where the map is positioned on the screen? Or where you are saving the cordinates to? You seem to be using it for both x_x. Also you seem to use to totally new variables when passing to the triggeraction...

Try...

NPC Code:

if (mousescreenx in | mapxy[0], mapxy[0] + 420 | && mousescreeny in | mapxy[1], mapxy[1] + 420 | ) {
if (keydown2(17, true)) {
this.tempxy = {mousescreenx-mapxy[0]*(16/7),mousescreeny-mapxy[1]*(16/7)};
triggeraction 0, 0, serverside, -Map, warp, #v(this.tempxy[0]),#v(this.tempxy[1]);
}
}



Now mapxy[] is the position of the map on the screen and tempxy[] is where we temporarily store the values when calculating them.

If there somthing glaringly wrong in what I posted, then blame lack of sleep :\

SSS 02-17-2005 11:16 AM

It doesnt seem to work, it might have been something I did wrong but Ive been working on it for about 10 minutes, still doesnt work properly..

Maybe i should give some more information ;)


mapxy = {screenwidth / 2 - 210, screenheight / 2 - 210};
The map is shown in the middle , it is 420x420.
Im trying to make it so if i click 0,0 on the map screen
i will be warped to 0,0
but if i click the very bottem right corner i will be warped to 957x957, or the very bottem corner

mapxy is where the map is shown on the screen
im trying to get the new player coordinates from the screen position on mapxy
to gmap position,so instead of 420x420 it would be 957x957
am i confusing? im sorta confusing myself :(

SSS 02-18-2005 08:09 AM

nobody knows? comon :(

Tolnaftate2004 02-18-2005 08:38 AM

NPC Code:

if (mousescreenx in | mapxy[0], mapxy[0] + 420 | && mousescreeny in | mapxy[1], mapxy[1] + 420 | ) {
if (keydown2(17, true)) {
this.tempxy = {(mousescreenx-mapxy[0])*(16/7),(mousescreeny-mapxy[1])*(16/7)};
triggeraction 0, 0, serverside, -Map, warp, #v(this.tempxy[0]),#v(this.tempxy[1]);
}
}


Polo 02-18-2005 11:47 AM

Oh yeah silly me forgot the brackets round the subtraction x_x

ApothiX 02-19-2005 03:11 AM

For security reasons, instead of triggeractioning a warp, you should just do like
setplayerprop #c,warpto #v(xcoord) #v(ycoord); or something.

SSS 02-19-2005 08:54 AM

It works now, thanks a lot :)

SSS 02-21-2005 07:54 AM

Having another problem, since Im not good with math.

Here it is, can anyone help?
Im trying to show where the player is on the custom map..
the custom map position is on the screen at
x(screenwidth / 2 - 210)
y(screenheight / 2 - 210)
the map image is shown there, the map image is 420x420
I cant figure the math out same map size as I used for the warping up there....
but it needs to show up using something like this.
showimg 201,@@@Me,this.x+playerx/420,this.y+playery/420;
changeimgvis 201,4;

any math experts out there that can help?

Dach 02-21-2005 09:43 PM

Quote:

Originally Posted by SSS
Having another problem, since Im not good with math.
[...]
showimg 201,@@@Me,this.x+playerx/420,this.y+playery/420;
changeimgvis 201,4;

Math lesson
We have three numbers, a b c and d (makes more sense for b and c to be vectors and a be a position on b and we are looking for the corresponding position, d, on b, but I doubt you have that kind of math knowledge :/ ) where 0<=a<=b and 0<=d<=c and we want to find d so that a/b = d/c. We work out the expression;
a/b = d/c
(a/b)*c = d
d = (a/b)*c

assuming that this.x and this.y are the map x and y;
we know 420 is the width and height of map image, and 960 is the width and height of the actual map in tiles, therefore using the above expression, a is playerx or y, b = 960, c = 420 and d is the x or y of the position on the map image. You can do the rest, if you can't I will personally beat you with a stick
:rolleyes:

SSS 02-24-2005 07:55 AM

Thanks for helping out, and not being an ******* about it because you have more math skills then me, not all of us have good education, some people just dont understand things the way others do..Everyones different and unique in their own way.


All times are GMT +2. The time now is 03:34 PM.

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