View Single Post
  #3  
Old 04-09-2010, 11:56 PM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura about
Send a message via AIM to adam
New updates.

Added:
  • Leaps
  • List of Objects to check for
  • No longer need to call InitializeTiles()


PHP Code:
testTiles(x,y,mode,leaps,list) 
Still all that's required is x and y to check for and return the name of what x and y is on.

Mode is the same, set to true if you wish the tiles to be replaced immediately.

Leaps, set to true to show leaps when tiles are replaced.

list, an array of TileObject definitions to search for, will only check for what's in the list. And will only replace what's in the list.

Example:
PHP Code:
function onCreated(){
  
join("personal_adam_testtiles");
  
this.TileObjects.add(newTileObject("BigRock",2,{{354,355,356,357},{370,371,372,373},{386,387,388,389},{402,403,404,405}},{{374,358,359,375},{423,301,301,407},{423,301,301,407},{392,376,377,361}}));
}
function 
onMouseDown(){
  
player.chat testTiles(mousex,mousey,true,true,{"Bush","Rock","BigRock"}).label;

Will replace the Bush and Rock and BigRock, with leaps when you click on them.


You will have to update custom tile definitions, by inserting the leap type right after the name, before the tile array.

PHP Code:
//NPC Created by Rogue Shadow (TCN)
//AIM: RogueTCN
// Run function InitializeTiles() to load definitions from here
// temp.test = testTiles(x,y,mode,leaps)   if mode is true, replace tiles found, if false return what was found
//#CLIENTSIDE
function InitializeTiles(){
    
//       Name,  leaptype,    Tiles to Find,             Tiles to Replace with
  
this.TileObjects.add(newTileObject("Bush",0, {{2,3},{18,19}} , {{0x2A5,0x2A6},{0x2B5,0x2B6}} ));
  
this.TileObjects.add(newTileObject("Swamp",1, {{ 420421},{436 ,437 }} , {{679680},{695 ,696 }} ));
  
this.TileObjects.add(newTileObject("Vase",2, {{684,685},{700,701}} , {{1770,1771},{1786,1787}} ));
  
this.TileObjects.add(newTileObject("Rock",2, {{34,35},{50,51}} , {{1834,1835},{1850,1851}} ));
  
this.TileObjects.add(newTileObject("BlackRock",2, {{990,991},{1006,1007}},{{1834,1835},{1850,1851}} ));
  
this.TileObjects.add(newTileObject("Sign",3, {{512,513},{528,529}} , {{1802,1803},{1818,1819}} ));
  
this.TileObjects.add(newTileObject("Stake",-1, {{1652,1653},{1668,1669}}, {{1802,1803},{1818,1819}} ));
  
this.TileObjects.add(newTileObject("Grass",-1, {{2047,2047},{2047,2047}} , {{1834,1835},{1850,1851}} ));
  
this.InitTileObjects true;
}
function 
newTileObject(label,leap,tiles,replace){
  
temp.to = new TStaticVar();
  
temp.to.label label;
  
temp.to.tiles tiles;
  
temp.to.replace replace;
  
temp.to.temp.to.tiles[0].size();
  
temp.to.temp.to.tiles.size();
  
temp.to.leap leap;
  return 
temp.to;
}
// if label is set it will only replace those tiles in the array
function testTiles(testx,testy,mode,leap,labelarray){//mode=true, replace tiles found, false, report name of tiles found
  
if (!this.InitTileObjects)InitializeTiles();
  if (
labelarray == false){
    
temp.obj this.TileObjects
  }else{
    for (
temp.othis.TileObjects){
      if (
temp.o.label in temp.labelarray){
        
temp.obj.add(temp.o);
      }
    }
  }
  
temp.test checkTiles(temp.testx,temp.testy,temp.obj);
  if (
temp.test != false){
    
temp.matchx temp.testx temp.test[0];
    
temp.matchy temp.testy temp.test[1];
    if (
matchTiles(temp.matchx,temp.matchy,temp.test[2])){
      if (
mode){
        
replaceTiles(temp.matchx,temp.matchy,temp.test[2]);
        if (
temp.leap){
          for (
temp.0;temp.temp.test[2].wtemp.+=2){
            for (
temp.0;temp.temp.test[2].htemp.+=2){
              
putleaps(temp.test[2].leap,temp.matchx+temp.i,temp.matchy+temp.j);
            }
          }
        }
        return 
temp.test[2];
      }else return 
temp.test[2];
    }
  }
  return 
false;
}
function 
checkTiles(testx,testy,obj) {
  
temp.tile tiles[temp.testx,temp.testy];
  for (
temp.otemp.obj){
    for (
temp.0temp.temp.o.wtemp.i++ ){
      for (
temp.0temp.temp.o.htemp.j++ ){
        if (
temp.tile == temp.o.tiles[temp.j][temp.i]){
          
temp.match = {temp.i,temp.j,temp.o};
          return 
temp.match;
        }
      }
    }
  }
  return 
false;
}
function 
matchTiles(tilex,tiley,obj){
  for (
temp.0temp.temp.obj.wtemp.i++){
    for (
temp.0temp.temp.obj.htemp.j++){
      if (
tiles[temp.i+temp.tilex,temp.j+temp.tiley] != temp.obj.tiles[temp.j][temp.i]){
        return 
false;
      }
    }
  }
  return 
true;
}
function 
replaceTiles(x,y,obj){
  for (
temp.0temp.<  temp.obj.wtemp.i++) {
    for (
temp.0temp.temp.obj.htemp.j++){
      
tiles[temp.i+x,temp.j+y] = temp.obj.replace[temp.j][temp.i];
      
updateboard(x,y,temp.obj.w,temp.obj.h);
    }
  }

__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly

Last edited by adam; 04-10-2010 at 07:24 AM..
Reply With Quote