Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   player.level with Gmaps (https://forums.graalonline.com/forums/showthread.php?t=134268365)

baseman101 06-26-2013 03:57 AM

player.level with Gmaps
 
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

Quote:

Originally Posted by cbk1994 (Post 1589587)
I usually put this into a player class:

PHP Code:

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



..

baseman101 06-26-2013 05:15 AM

Quote:

Originally Posted by cbk1994 (Post 1719789)
..

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

PHP Code:

findPlayerByCommunityName(this.plAcc).level.getmappartfile(findPlayerByCommunityName(this.plAcc).xfindPlayerByCommunityName(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

Quote:

Originally Posted by baseman101 (Post 1719790)
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...

PHP Code:

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):

PHP Code:

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.xtemp.pl.y);
  }
  
  return 
temp.pl.level.name;



baseman101 06-26-2013 05:26 AM

Quote:

Originally Posted by cbk1994 (Post 1719791)
The best solution would be to stick that function into any class joined to the player. Then you can just do...

PHP Code:

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):

PHP Code:

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.xtemp.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

Quote:

Originally Posted by baseman101 (Post 1719792)
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):

PHP Code:

temp.temp.pl.64;
temp.temp.pl.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

Quote:

Originally Posted by cbk1994 (Post 1719793)
Just take the player's x and y mod 64 (the width/height of a level):

PHP Code:

temp.temp.pl.64;
temp.temp.pl.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.
PHP Code:

tiles[temp.x,temp.y] = findlevel("test_d04.nw").tiles[temp.x,temp.y]; 

Doesn't work, connected to the gmap
PHP Code:

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

PHP Code:

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

Quote:

Originally Posted by baseman101 (Post 1719823)
PHP Code:

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

PHP Code:

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

and check if its returning the correct number

baseman101 06-26-2013 04:40 PM

Quote:

Originally Posted by callimuc (Post 1719825)
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

PHP Code:

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

Quote:

Originally Posted by baseman101 (Post 1719795)
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.
PHP Code:

tiles[temp.x,temp.y] = findlevel("test_d04.nw").tiles[temp.x,temp.y]; 

Doesn't work, connected to the gmap
PHP Code:

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

PHP Code:

temp.pl findPlayer2(this.plAcc);

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

// get the level's tiles using the offset
for (temp.0temp.64temp.++) {
  for (
temp.0temp.64temp.++) {
    
temp.tile temp.pl.level.tiles[temp.temp.offsetxtemp.temp.offsety];
  }


Quote:

Originally Posted by callimuc (Post 1719819)
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.


All times are GMT +2. The time now is 08:31 PM.

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