Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-26-2013, 03:57 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
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
Reply With Quote
  #2  
Old 06-26-2013, 05:07 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by cbk1994 View Post
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;

..
__________________
Reply With Quote
  #3  
Old 06-26-2013, 05:15 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
..
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?
Reply With Quote
  #4  
Old 06-26-2013, 05:20 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by baseman101 View Post
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;

__________________
Reply With Quote
  #5  
Old 06-26-2013, 05:26 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
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.
Reply With Quote
  #6  
Old 06-26-2013, 05:31 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by baseman101 View Post
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.
__________________
Reply With Quote
  #7  
Old 06-26-2013, 05:32 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
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
Reply With Quote
  #8  
Old 06-26-2013, 06:23 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
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

Last edited by baseman101; 06-26-2013 at 06:56 AM..
Reply With Quote
  #9  
Old 06-26-2013, 03:18 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
regarding level name: using player.level.name should also return the level name instead of the gmaps name
__________________
MEEP!
Reply With Quote
  #10  
Old 06-26-2013, 04:15 PM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
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?
Reply With Quote
  #11  
Old 06-26-2013, 04:34 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by baseman101 View Post
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
__________________
MEEP!
Reply With Quote
  #12  
Old 06-26-2013, 04:40 PM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
Quote:
Originally Posted by callimuc View Post
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
Reply With Quote
  #13  
Old 06-26-2013, 05:00 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by baseman101 View Post
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 View Post
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.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:10 PM.


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