Thread: onWall3()
View Single Post
  #1  
Old 08-22-2013, 05:20 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
onWall3()

Just a make shift version of the onWall2() function that checks the tilelayers on serverside, which currently isn't implemented in-game yet.

Use :
onWall3( x, y, w, h, level, layerscount);
  • x - The level's X coordinate to check (integer)
  • y - The level's Y coordinate to check (integer)
  • w - The width of tiles to check (integer)
  • h - The height of tiles to check (integer)
  • level - The name of the level to check (string)
  • layerscount - The number of layers to check from layer 0 (integer)

Installation :
Simply add the following code to a class, then join that class to whatever you need it for serverside. Also upload the 'tiledata.nw' file to your levels/ folder and I guess make sure the NPC server has read rights to the levels/ folder

PHP Code:
public function onWall3( temp.lvl_x, temp.lvl_y, temp.w, temp.h, temp.lvl, temp.lvl_c)
{

  
temp.file_data.loadLines( "levels/" @ temp.lvl);
  
  
this.delete_rest = false;
  
  
temp.file_lines = temp.level_data.size();

  for ( 
temp.a : temp.file_data)
  {
  
    
temp.tokens = temp.a.tokenize();

    if ( 
temp.tokens[ 0] == "BOARD")
      
temp.level_data.add( temp.tokens);

  }
  
  for ( 
temp.c = 0; temp.c < temp.w; temp.c ++;)
  {
  
    for ( 
temp.b = 0; temp.b < temp.h; temp.b ++;)
    {
    
      for ( 
temp.a = 0; temp.a < temp.lvl_c; temp.a ++;)
      {

        
temp.tile_loc = getTileLocation( base64ToTile( temp.level_data[( temp.b + temp.lvl_y) + ( temp.a * 64)][ 5].substring(( temp.c + temp.lvl_x) * 2, 2)));
    
        if ( 
findLevel( "tiledata.nw").onwall( temp.tile_loc[ 0] % 64, temp.tile_loc[ 1] + ( 32 * temp.tile_loc[ 0] > 64? 1 : 0)))
        {
    
          
temp.isBlocking = true;
          break;
  
        }
      }
      
      if ( 
temp.isBlocking)
        break;
        
    }
    
    if ( 
temp.isBlocking)
      break;
        
  }
  
  return 
float( temp.isBlocking);
  
}



function 
Base64ToTile( temp.t) // Big thank you to Dusty for this function 
{
  
temp.base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  
  if ( 
temp.t.type() == 1) 
  {
  
    return 
temp.base64.pos( temp.t.substring( 0, 1)) * 64 + temp.base64.pos( temp.t.substring( 1, 1));
  } 
  
  else if ( 
temp.t.type() == 3) 
  {
  
    
temp.decodearray = new[ 0];
    
    for ( 
temp.i : temp.t) 
      
temp.decodearray.add( temp.base64.pos( temp.i.substring( 0, 1)) * 64 + temp.base64.pos( temp.i.substring( 1, 1))); 
    
    return 
temp.decodearray;
  } 
  
  else 
    return -
1;

}

function 
getTileLocation( temp.tileNum) //Returns tileset coordinate from hexa/decimal
{

  
temp.tileX = int( temp.tileNum / 512) * 16 + ( temp.tileNum % 16);
  
temp.tileY = int( temp.tileNum / 16) % 32; 
  return { 
temp.tileX, temp.tileY}; 

} 
Example :
Make a weapon, add this code to it, and then add it to yourself. It will then check a 2x2 square if the tiles are blocking.

PHP Code:
function onCreated()
{

  
this.join( "core");

}

function 
onActionServerside()
{

  if ( 
params[ 0] == "onWall3")
    echo( 
onWall3( params[ 1], params[ 2], params[ 3], params[ 4], params[ 5], params[ 6]));

}

//#CLIENTSIDE

function GraalControl.onMouseDown()
{

  
triggerServer( "weapon", this.name, "onWall3", int( mousex), int( mousey), 2, 2, player.level.name, tilelayercount);
  
showimg( 1, "block.png", int( mousex), int( mousey));
   
} 
Also, I'm pretty sure there are several way to make this more efficient, if so please correct my method.

Also figured I should attach this for getting the actual level name and not gmap name serverside, credit goes to cbk1994 for the code. -Thank you. =]
PHP Code:
public function getPreciseLevelName() {
  if (
this.level.name.ends(".gmap")) {
    return 
this.level.getmappartfile(this.x, this.y);
  }
  
  return 
this.level.name;
} 
Attached Files
File Type: nw tiledata.nw (9.1 KB, 286 views)
__________________
Deep into the Darkness peering...

Last edited by Angel_Light; 08-22-2013 at 04:54 PM..
Reply With Quote