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;
}