Thread: onWall3()
View Single Post
  #7  
Old 08-28-2013, 08: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 :
PHP 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.

PHP 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 11:34 AM..
Reply With Quote