PDA

View Full Version : player.level with Gmaps


baseman101
06-26-2013, 03:57 AM
Hello,

I've made a script that spy's on a player, so that hackers that can see past our alpha won't realize that we're spying on them. There's a small problem, if the person goes on a GMap, the script will show the top left of the gmap. I know how to fix that, and that is finding the level name of the "chunk" in the gmap.

For example, currently player.level will show that he's in whatever.gmap. How would I show the exact level he's in, and the coordinates?

e.g whatever_d6.nw

cbk1994
06-26-2013, 05:07 AM
I usually put this into a player class:


public function getPreciseLevelName() {
if (this.level.name.ends(".gmap")) {
return this.level.getmappartfile(this.x, this.y);
}

return this.level.name;
}

..

baseman101
06-26-2013, 05:15 AM
..

Thanks, I'll try this as soon as possible! So, in my example, you would do:


findPlayerByCommunityName(this.plAcc).level.getmap partfile(findPlayerByCommunityName(this.plAcc).x, findPlayerByCommunityName(this.plAcc).y);
//this returns the map chunk that the player is positioned in


How would I find the exact player's position in the map part? For example, not the whole gmap, but in that specific level part?

cbk1994
06-26-2013, 05:20 AM
How would I find the exact player's position in the map part? For example, not the whole gmap, but in that specific level part?

The best solution would be to stick that function into any class joined to the player. Then you can just do...


temp.pl = findPlayer2(this.plAcc);
echo(temp.pl.getPreciseLevelName());


Alternatively if you don't want to mess with the player class, you can do it like this (but it's a bit sloppier, and it's a handy function to have in the player class anyway):


function onCreated() {
temp.pl = findPlayer2(this.plAcc);
echo(this.getPreciseLevelName(temp.pl));
}

function getPreciseLevelName(temp.pl) {
if (temp.pl.level.name.ends(".gmap")) {
return temp.pl.level.getmappartfile(temp.pl.x, temp.pl.y);
}

return temp.pl.level.name;
}

baseman101
06-26-2013, 05:26 AM
The best solution would be to stick that function into any class joined to the player. Then you can just do...


temp.pl = findPlayer2(this.plAcc);
echo(temp.pl.getPreciseLevelName());


Alternatively if you don't want to mess with the player class, you can do it like this (but it's a bit sloppier, and it's a handy function to have in the player class anyway):


function onCreated() {
temp.pl = findPlayer2(this.plAcc);
echo(this.getPreciseLevelName(temp.pl));
}

function getPreciseLevelName(temp.pl) {
if (temp.pl.level.name.ends(".gmap")) {
return temp.pl.level.getmappartfile(temp.pl.x, temp.pl.y);
}

return temp.pl.level.name;
}

Sorry, I wasn't clarifying myself. I meant the x and y coordinates of the level part.

cbk1994
06-26-2013, 05:31 AM
Sorry, I wasn't clarifying myself. I meant the x and y coordinates of the level part.

Just take the player's x and y mod 64 (the width/height of a level):


temp.x = temp.pl.x % 64;
temp.y = temp.pl.y % 64;


% is the modulo operator (the remainder of division).

This will give you the player's x/y relative to the top-left of their current level, rather than the top-left of the entire GMAP.

baseman101
06-26-2013, 05:32 AM
Just take the player's x and y mod 64 (the width/height of a level):


temp.x = temp.pl.x % 64;
temp.y = temp.pl.y % 64;


% is the modulo operator (the remainder of division).

This will give you the player's x/y relative to the top-left of their current level, rather than the top-left of the entire GMAP.

Thank you very much! You were a giant help, kudos

baseman101
06-26-2013, 06:23 AM
Hey, final problem. When I try to copy the tiles from a level on the Gmap, it doesn't work. However, when I do a normal level, it does work.
tiles[temp.x,temp.y] = findlevel("test_d04.nw").tiles[temp.x,temp.y];
Doesn't work, connected to the gmap
tiles[temp.x,temp.y] = findlevel("test.nw").tiles[temp.x,temp.y];
Works, not connected to the gmap

callimuc
06-26-2013, 03:18 PM
regarding level name: using player.level.name should also return the level name instead of the gmaps name

baseman101
06-26-2013, 04:15 PM
function onPlayerChats() {
if(player.chat == "/try") {
echo(player.level.name);
}
}

This returns something.gmap. Anyway, what about the problem with getting the tiles of a gmap part?

callimuc
06-26-2013, 04:34 PM
function onPlayerChats() {
if(player.chat == "/try") {
echo(player.level.name);
}
}

This returns something.gmap. Anyway, what about the problem with getting the tiles of a gmap part?

hmm and on serverside @ level thingy?

and I'm not too sure about the tile thing. maybe show us how you did the change (loops etc)? can you even read them? check that by doing something like

echo(findLevel(levelname).tiles[1,1]);

and check if its returning the correct number

baseman101
06-26-2013, 04:40 PM
hmm and on serverside @ level thingy?

and I'm not too sure about the tile thing. maybe show us how you did the change (loops etc)? can you even read them? check that by doing something like

echo(findLevel(levelname).tiles[1,1]);

and check if its returning the correct number

It returns 0, which is not the right tile ID. No idea what's up x-x

cbk1994
06-26-2013, 05:00 PM
Hey, final problem. When I try to copy the tiles from a level on the Gmap, it doesn't work. However, when I do a normal level, it does work.
tiles[temp.x,temp.y] = findlevel("test_d04.nw").tiles[temp.x,temp.y];
Doesn't work, connected to the gmap
tiles[temp.x,temp.y] = findlevel("test.nw").tiles[temp.x,temp.y];
Works, not connected to the gmap

I don't think you'll be able to get this to work. findLevel is returning the level object, and on serverside a GMAP is treated like one big level.

The best solution would be to simply calculate the offset of the player's current level on the GMAP, and figure out the tiles relative to that offset. Something like


temp.pl = findPlayer2(this.plAcc);

// offset of the current level on the GMAP in tiles
temp.offsetx = int(temp.pl.x / 64) * 64;
temp.offsety = int(temp.pl.y / 64) * 64;

// get the level's tiles using the offset
for (temp.x = 0; temp.x < 64; temp.x ++) {
for (temp.y = 0; temp.y < 64; temp.y ++) {
temp.tile = temp.pl.level.tiles[temp.x + temp.offsetx, temp.y + temp.offsety];
}
}


regarding level name: using player.level.name should also return the level name instead of the gmaps name

On serverside, if the GMAP is setup correctly, it will return the GMAP name, since the NPC-server sees the GMAP as one big TServerLevel.