Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2015-04-24 17:12:00, last edited by Hexagon (2015-04-24 17:12:15)

Hexagon
Member
Joined: 2015-04-22
Posts: 1,213

[Help] Movement events have strange values

I got a move packet. I'm interested in the X and Y position of the player. Is there something that I have to divide them by to get it in terms of blocks on the map? The Y axis is not long enough and the X axis is too short (relative to the world.)

I'm trying to overlay them on a map, and I have to stretch the coordinates, and it's not making sense to me.

Offline

Wooted by: (2)

#2 2015-04-24 17:40:21, last edited by ZeldaXD (2015-04-24 17:40:38)

ZeldaXD
EE Homeboy
From: Cyprus
Joined: 2015-02-15
Posts: 1,539
Website

Re: [Help] Movement events have strange values

                                int x = (int)Math.Round(m.GetDouble(1) / 16);
                                int y = (int)Math.Round(m.GetDouble(2) / 16);

hope it helps.


gLjTZE1.png

Offline

Wooted by: (3)

#3 2015-04-24 18:35:59

Hexagon
Member
Joined: 2015-04-22
Posts: 1,213

Re: [Help] Movement events have strange values

Thanks! I did something wrong initially now it works.

Offline

Wooted by: (2)

#4 2015-04-25 00:34:56, last edited by Xfrogman43 (2015-04-25 00:35:53)

Xfrogman43
Member
From: need to find a new home
Joined: 2015-02-15
Posts: 4,174

Re: [Help] Movement events have strange values

                                int x = m.GetInt((1) / 16);
                                int y =m.GetInt((2) / 16);

Haven't done movement in a while, but isn't that the same thing?


zsbu6Xm.png thanks zoey aaaaaaaaaaaand thanks latif for the avatar

Offline

Wooted by:

#5 2015-04-25 07:42:59, last edited by Srna (2015-04-25 07:43:27)

Srna
Member
Joined: 2015-02-26
Posts: 220

Re: [Help] Movement events have strange values

xfrogman43 wrote:

int x = m.GetInt((1) / 16);
                                int y =m.GetInt((2) / 16);

I tried that before and it didnt work :/

Fix:

int x = (int)(m.GetInt(1)) / 16;
int y = (int)(m.GetInt(2)) / 16;

Offline

Wooted by:

#6 2015-04-25 07:56:57, last edited by DarkDragon4900 (2015-04-25 08:02:23)

DarkDragon4900
Member
Joined: 2015-03-17
Posts: 251

Re: [Help] Movement events have strange values

Srna wrote:
xfrogman43 wrote:

int x = m.GetInt((1) / 16);
                                int y =m.GetInt((2) / 16);

I tried that before and it didnt work :/

Fix:

int x = (int)(m.GetInt(1)) / 16;
int y = (int)(m.GetInt(2)) / 16;

The values at 1 & 2 are doubles.

You have to use GetDouble and round them since they can be something like 2160.349298398 and that is not an int. unless you round it.
And dividing it by 16 gives you the block coords they're on.
The reason it's multiplied by 16 is probs the size of the smiley. since the location needs to be accurate.

Offline

Wooted by:

#7 2015-04-25 12:48:51

Hexagon
Member
Joined: 2015-04-22
Posts: 1,213

Re: [Help] Movement events have strange values

Wait, why do they have to be ints? If it's just dividing by 16 which gives the right value, then m.GetDouble(1)/(double)16 would work.

Offline

Wooted by:

#8 2015-04-26 11:03:05

DarkDragon4900
Member
Joined: 2015-03-17
Posts: 251

Re: [Help] Movement events have strange values

Unless you want it to give you int values for the loc, then the code you posted should work except you don't need the "(double)" as 16 counts as a double, too.

Offline

Wooted by:

#9 2015-04-26 12:20:51

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: [Help] Movement events have strange values

To fill up DarkDragon4900's statement:

DarkDragon4900 wrote:

you don't need the "(double)" as 16 counts as a double, too.

Every integer can be typecasted into a double, and will be done automatically if it has to be done.
Officially 16 counts as an integer, but the compiler converts it into a double, as it notices a double is required.
And a bit quicker way (in my opinion) to covert 16 into a double would be by declaring it as such '16.0'. (When you're have an int variable you indeed would have to use '(double)[variable]')

Offline

Wooted by:

#10 2015-04-26 12:35:03

madiik
Member
From: floor above Yuuta
Joined: 2015-02-26
Posts: 514

Re: [Help] Movement events have strange values

Actually, what you should do is convert them to int first, then divide with 16.

Because dividing a double with decimals would have bad consequences.

It would return offset positions. Compare.


shh i have returned

Offline

Wooted by:

#11 2015-04-27 12:28:09, last edited by DarkDragon4900 (2015-04-27 12:28:40)

DarkDragon4900
Member
Joined: 2015-03-17
Posts: 251

Re: [Help] Movement events have strange values

den3107 wrote:

To fill up DarkDragon4900's statement:

DarkDragon4900 wrote:

you don't need the "(double)" as 16 counts as a double, too.

Every integer can be typecasted into a double, and will be done automatically if it has to be done.
Officially 16 counts as an integer, but the compiler converts it into a double, as it notices a double is required.
And a bit quicker way (in my opinion) to covert 16 into a double would be by declaring it as such '16.0'. (When you're have an int variable you indeed would have to use '(double)[variable]')

I added the

DarkDragon4900 wrote:

, too

to indicate that it isn't a double by default :p


madiik wrote:

Actually, what you should do is convert them to int first, then divide with 16.

Because dividing a double with decimals would have bad consequences.

It would return offset positions. Compare.

I guess i'd agree with this.

Offline

Wooted by:
DarkDragon49001430134089499281

Board footer

Powered by FluxBB

[ Started around 1732490787.187 - Generated in 0.058 seconds, 12 queries executed - Memory usage: 1.54 MiB (Peak: 1.71 MiB) ]