Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Tile Checking (https://forums.graalonline.com/forums/showthread.php?t=80715)

Switch 07-22-2008 04:41 AM

Tile Checking
 
As I'm trying to fix the shovel on Zenkou, which I'm almost done fixing for the known bugs, I need to know how to check if one tile is in the same level as another.

I know it sounds wierd but let me explain.
If you're digging for a shell (diggable in sand only) and you're in the middle of the jungle and dig on sand, you can still get a shell. That's kind of improbable in real terms. So what I'm trying to do is find out how to check in the sand tile is in the same level as a deepwater tile.

All I really need to know is how to check the tile in a script.
For example, these 2 tiles are grass tiles on Zenkou.
PHP Code:

0x31,0x1A4 

So I see that a tile can be either a "number x(by) number" or "number x(by) letters/numbers".
This is confusing to me because I've never worked with tiles I didn't already have in a script.

What I'm asking for is help with figuring out what a certain tile is.

DustyPorViva 07-22-2008 04:50 AM

Well you can run a loop when the player enters a level like...

PHP Code:

function onPlayerenters() {
  for (
i=0;i<64*64;i++) { // check every tile in the level
    
if (tiles[i%64,int(i/64)] == watertilehex) { // this would have to be edited to check the current level, as on a gmap this would just check the top left corner
      
this.levelcontainswater true// yes, there's water in the level
      
break; // no need to check for more water, right? So let's stop checking!
    
}
  }


The problem with this is the fact that depending on the levels, you could be right next to water, but there will actually be no water in your current level(because of gmaps), so it could end up reading as false. So instead of checking the level, just check the tiles surrounding the player?

An even simpler method would just be using level.vars!

Switch 07-22-2008 04:54 AM

Quote:

Originally Posted by DustyPorViva (Post 1406746)
Well you can run a loop when the player enters a level like...

PHP Code:

function onPlayerenters() {
  for (
i=0;i<64*64;i++) {
    if (
tiles[i%64,int(i/64)] == watertilehex) {
      
this.levelcontainswater true;
      break; 
// no need to check for more water, right?
    
}
  }



I guess, but I want it to be a little more simple to blend with the script it'll be put into, so I just want to know how to find a tile "blank"x"blank"

cbk1994 07-22-2008 04:55 AM

Quote:

Originally Posted by Switch (Post 1406749)
I guess, but I want it to be a little more simple to blend with the script it'll be put into, so I just want to know how to find a tile "blank"x"blank"

tiles[ dx, dy ]

Switch 07-22-2008 05:13 AM

Quote:

Originally Posted by cbk1994 (Post 1406750)
tiles[ dx, dy ]

explain what the d is, please?

DustyPorViva 07-22-2008 05:16 AM

Heh... nothing. Typically it's for delta but there is no delta in this case.

Tiles[x,y] is what you're looking for... which is the same. Now what you do is...

tiles[x,y](x and y are... well, the x and y you're checking) == hex.

So...
if (tiles[x,y] in {0x31,0x1A4}) {}
Would check if the tiles at the given position match what you provided in the original post.

Loriel 07-22-2008 05:20 AM

Quote:

Originally Posted by Switch (Post 1406740)
PHP Code:

0x31,0x1A4 


Those are hexadecimal numbers. That is just fancy syntax for regular numbers. The "0x" just means that the number is given in base 16, not base 10 as numbers usually are. You can look up the details on the internet, but as you are not going to do math with them manually, you do not really have to care because you can stuff them into variables or whatever and use them like regular numbers.

You use tiles[x, y] to check the number (as above) of the tile at x, y in the current level. You can compare it against the number of your water tile or whatever.

Checking whether a given tile is present in the current level is not going to get any easier than for-loops to check every tile on its own. Just put it into a function.

It might be easier to just flag all levels that are supposed to yield shells by putting an NPC that does something like level.canDigForShells = true, or however that works.

haro41 07-22-2008 07:04 AM

yes but this will be a fairly large list of levels, given the style of our playerworld. completed, this list could top 300+

i guess an alternative we could do is to rename all the levels that would have seashells to end with beach.nw
i guess that wouldnt take to long, and then also we would have to edit the gmap file. anything else with this solution?

WhiteDragon 07-22-2008 07:38 AM

You could just drop a
PHP Code:

join("spawn_seashells"); 

NPC in the level and then alter the shovel accordingly.



Or, you could check outwards from the point to a certain radius on the tiles.

PHP Code:

// Archimedean spiral
this.1// turns the spiral
this.1// distance between successive turns
this.thetaMax pi// increasing this will make it spiral out farther
this.tileRange = {0x31,0x1A4};
function 
polarToCartesian(temp.polarCoord) {
  return {
            
temp.polarCoord[0]*cos(temp.polarCoord[1]),
            
temp.polarCoord[0]*sin(temp.polarCoord[1])
           };
}
function 
onDig(temp.coord) { // no idea how you're doing this, but let's say onDig() get's called with {x,y} of the dig spot
  
for (temp.theta 0temp.theta this.thetaMaxtemp.theta+= pi/16) {
    
temp.normalizedCoord polarToCartesian({this.this.b*temp.thetatemp.theta});
    if (
tiles[temp.normalizedCoord[0]+temp.coord[0], temp.normalizedCoord[1]+temp.coord[1]] in this.tileRange) {
      
this.closeToWater true;
      break;
    }
  }
  if (
this.closeToWater) {
    
//woot
  
}


No idea if this will actually work, but the concept is there.

Probably the first way would be easier.

Loriel 07-22-2008 01:46 PM

Quote:

Originally Posted by haro41 (Post 1406802)
yes but this will be a fairly large list of levels, given the style of our playerworld. completed, this list could top 300+

Adding NPCs to levels does not take that long :)

Quote:

i guess an alternative we could do is to rename all the levels that would have seashells to end with beach.nw
i guess that wouldnt take to long, and then also we would have to edit the gmap file. anything else with this solution?
Well, it is ugly, and if you want to do something similar for another item again you have to do it differently anyway. Changing all the names, links, gmap entries and other levels that setlevel2 to those levels is probably going to take longer than having a batch file add another NPC.

DustyPorViva 07-22-2008 05:28 PM

Quote:

Originally Posted by haro41 (Post 1406802)
yes but this will be a fairly large list of levels, given the style of our playerworld. completed, this list could top 300+

That's what you have lackies for.


All times are GMT +2. The time now is 06:12 PM.

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