Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-22-2013, 06: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

Graal Script Code:
public function onWall3temp.lvl_xtemp.lvl_ytemp.wtemp.htemp.lvltemp.lvl_c)
{

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

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

    if ( 
temp.tokens0] == "BOARD")
      
temp.level_data.addtemp.tokens);

  }
  
  for ( 
temp.0temp.temp.wtemp.++;)
  {
  
    for ( 
temp.0temp.temp.htemp.++;)
    {
    
      for ( 
temp.0temp.temp.lvl_ctemp.++;)
      {

        
temp.tile_loc getTileLocationbase64ToTiletemp.level_data[( temp.temp.lvl_y) + ( temp.64)][ 5].substring(( temp.temp.lvl_x) * 22)));
    
        if ( 
findLevel"tiledata.nw").onwalltemp.tile_loc0] % 64temp.tile_loc1] + ( 32 temp.tile_loc0] > 640)))
        {
    
          
temp.isBlocking true;
          break;
  
        }
      }
      
      if ( 
temp.isBlocking)
        break;
        
    }
    
    if ( 
temp.isBlocking)
      break;
        
  }
  
  return 
floattemp.isBlocking);
  
}



function 
Base64ToTiletemp.t// Big thank you to Dusty for this function 
{
  
temp.base64 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  
  if ( 
temp.t.type() == 1
  {
  
    return 
temp.base64.postemp.t.substring01)) * 64 temp.base64.postemp.t.substring11));
  } 
  
  else if ( 
temp.t.type() == 3
  {
  
    
temp.decodearray = new[ 0];
    
    for ( 
temp.temp.t
      
temp.decodearray.addtemp.base64.postemp.i.substring01)) * 64 temp.base64.postemp.i.substring11))); 
    
    return 
temp.decodearray;
  } 
  
  else 
    return -
1;

}

function 
getTileLocationtemp.tileNum//Returns tileset coordinate from hexa/decimal
{

  
temp.tileX inttemp.tileNum 512) * 16 + ( temp.tileNum 16);
  
temp.tileY inttemp.tileNum 16) % 32
  return { 
temp.tileXtemp.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.

Graal Script Code:
function onCreated()
{

  
this.join"core");

}

function 
onActionServerside()
{

  if ( 
params0] == "onWall3")
    echo( 
onWall3params1], params2], params3], params4], params5], params6]));

}

//#CLIENTSIDE

function GraalControl.onMouseDown()
{

  
triggerServer"weapon"this.name"onWall3"intmousex), intmousey), 22player.level.nametilelayercount);
  
showimg1"block.png"intmousex), intmousey));
   

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. =]
Graal Script Code:
public function getPreciseLevelName() {
  if (
this.level.name.ends(".gmap")) {
    return 
this.level.getmappartfile(this.xthis.y);
  }
  
  return 
this.level.name;

Attached Files
File Type: nw tiledata.nw (9.1 KB, 78 views)
__________________
Deep into the Darkness peering...

Last edited by Angel_Light; 08-22-2013 at 05:54 PM..
Reply With Quote
  #2  
Old 08-22-2013, 04:13 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,727
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
very nice, I would have loved this a year ago when I tried to convince Thor to use tilelayers on Classic.
__________________
Save Classic!
Reply With Quote
  #3  
Old 08-22-2013, 05:26 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
What is tiledata.nw supposed to be?
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #4  
Old 08-22-2013, 05:55 PM
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
Quote:
Originally Posted by xXziroXx View Post
What is tiledata.nw supposed to be?
Gah sorry, uploaded it. tiledata.nw is just how I checked which tiles on the tileset that are blocking or not. Uploaded it now.
__________________
Deep into the Darkness peering...

Last edited by Angel_Light; 08-23-2013 at 05:22 AM..
Reply With Quote
  #5  
Old 08-23-2013, 12:12 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
You would be better off determining all the blocking areas, caching the blocking data, and then referencing your cache (perhaps in a level var) instead of reloading and parsing the direct level data every time.
__________________
Quote:
Reply With Quote
  #6  
Old 08-23-2013, 04:46 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is a jewel in the roughTricxta is a jewel in the rough
Quote:
Originally Posted by fowlplay4 View Post
You would be better off determining all the blocking areas, caching the blocking data, and then referencing your cache (perhaps in a level var) instead of reloading and parsing the direct level data every time.
So then you'd need to rework weapons(e.g. the hammer) that change tiles to refresh the cache I guess? Seems like a bit of a hassle, besides... when was efficiency ever a major concern in graal development to the common developer?
__________________
Quote:
Originally Posted by Crono View Post
No look at it, Stefan is totally trolling Thor. Calling Classic a "playerworld" (something it's not supposed to be) is the ultimate subtle insult to a true fan.

It's genius.
Reply With Quote
  #7  
Old 08-28-2013, 09:06 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
Bit modified version that is taking lot less CPU. Changed it so a 'block map' of a level is created and I reference that instead of loading the level each time and looking at it. Probably be better to use level.vars instead of a db_npc, but I can't get level vars to work for me properly. :/ Also haven't added gmap support for building block maps. Feel free to modify/add to the script if you want.

Now with this method you personally have to build the block map by saying a command on RC

RC Command
/npc blockmap <level_name.nw> <# of layers>

Use
onWall3( x, y, w, h);

Installation

In your Control-NPC add this :
Graal Script Code:
function onRCChat()
{

  if ( 
params0] == "blockmap")
  {

    if ( !
levelExistsparams1]))
    {
  
      echo( 
"Control-NPC : Could not find" SPC params1] @ "!");
      return;
  
    }

    
this.lvl        params1];
    
this.layers     params2]; 
    
temp.file_data.loadLines"levels/" this.lvl);
    echo( 
"Control-NPC : Building block map for" SPC this.lvl ".");

    for ( 
temp.temp.file_data)
    {
    
      
temp.tokens temp.a.tokenize();
    
      if ( 
temp.tokens0] == "BOARD")
        
this.level_data.addtemp.tokens);
  
    }

    
onStartCount(); 

  }
}


function 
onStartCount()
{

  for ( 
temp.0temp.64temp.++;) // width
  
{

    
temp.isBlocking false;
    
    for ( 
temp.0temp.this.layerstemp.++;) // layer
    
{

      
temp.tile_loc getTileLocationbase64ToTilethis.level_datathis.count + ( temp.64)][ 5].substringtemp.22)));
      
      
      if ( 
findLevel"tiledata.nw").onwalltemp.tile_loc0] % 64temp.tile_loc1] + ( 32 * ( temp.tile_loc0] > 640))))
      {
      
        
temp.isBlocking true;
        break
        
      }    
    }

    
temp.data0.addtemp.isBlocking);

  }

  
this.data1.addtemp.data0);
  
  if ( 
this.count 63)
  {
  
    
this.count ++;
    
scheduleEvent0.1"onStartCount"); //Only way I could figure to avoid the maxlooplimit if you are doing several layers.
    
  
}
  
  else
  {
  
    
this.( @ "level_" this.lvl.substring0this.lvl.length() - 3)) = this.data1;
    echo( 
"Control-NPC : Block map for" SPC this.lvl ", has been built.");
    
this.count this.data1 this.layers this.level_data this.lvl NULL;
    
  }
}

function 
Base64ToTiletemp.t// Big thank you to Dusty for this function 
{
  
temp.base64 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  
  if ( 
temp.t.type() == 1
  {
  
    return 
temp.base64.postemp.t.substring01)) * 64 temp.base64.postemp.t.substring11));
  } 
  
  else if ( 
temp.t.type() == 3
  {
  
    
temp.decodearray = new[ 0];
    
    for ( 
temp.temp.t
      
temp.decodearray.addtemp.base64.postemp.i.substring01)) * 64 temp.base64.postemp.i.substring11))); 
    
    return 
temp.decodearray;
  } 
  
  else 
    return -
1;

}

function 
getTileLocationtemp.tileNum//Returns tileset coordinate from decimal
{

  
temp.tileX inttemp.tileNum 512) * 16 + ( temp.tileNum 16);
  
temp.tileY inttemp.tileNum 16) % 32
  return { 
temp.tileXtemp.tileY}; 


Next in a class put this.

Graal Script Code:
public function getPreciseLevelName()  // Thank you cbk1994
{

  if ( 
this.level.name.ends".gmap"))
    return 
this.level.getmappartfilethis.xthis.y);

  return 
this.level.name;
  


public function 
onWall3temp.lvl_xtemp.lvl_ytemp.wtemp.h)
{
  
  
temp.check findNPC"Control-NPC").( "level_" getPreciseLevelName().substring0getPreciseLevelName().length() - 3));
  
  for ( 
temp.0temp.temp.htemp.++;)
  {
  
    for ( 
temp.0temp.temp.wtemp.++;)
    {
   
      if (  
temp.checktemp.lvl_y temp.a][ temp.lvl_x temp.b] == 1)
        return 
true;
    
    }
  }
  
  return 
false;
  

Then in your baddie script or whatever, add the class with that script in it and just replace where ever you put onWall2, with onWall3.

I know this is more efficient due the /stats telling me, my baddie class CPU usage went from 1.784367163 % to 0.651127497 %. Although it does seem to spike from time to time. :/

e. May of had to do with other parts of the script for the high cpu usage, after rewriting a good portion to be cleaner and more efficient, the time is down to 0.063054958 %, but that is showing how efficient it is still.
__________________
Deep into the Darkness peering...

Last edited by Angel_Light; 08-28-2013 at 12:34 PM..
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 06:56 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.