Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   testTiles(x,y,mode) (https://forums.graalonline.com/forums/showthread.php?t=134258695)

adam 04-09-2010 01:41 AM

testTiles(x,y,mode)
 
Use this to #1 check for and replace the tiles of Bushes, Swamps, Stones, Black Stones, Signs, Stakes, Vase, Dig a hole in grass.
#2 to check for your own arrangement of tiles, and what to replace it with. Or just do checking for something. example: a quest for which the user must find a bomy statue etc...

PHP Code:

//NPC Created by Rogue Shadow (TCN)

//#CLIENTSIDE

function onCreated(){
  
join("personal_adam_testtiles");
  
InitializeTiles(); // call this function to load the predefined tile objects in the...
  // ...class below
  // example of how to add your own definitions
  // name, 2d array of tiles to find, 2d array of tiles to replace, if you only
 // want to check for a certain arrangement of tiles, you can omit  the
 // replace tiles, but it will automatically use tile 0 if you try to replace.
  
this.TileObjects.add(newTileObject("BigRock",{{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(){
  
temp.tx int(mousex);
  
temp.ty int(mousey); // just checks at the mousex/mousey doesn't replace
  
player.chat testTiles(temp.tx,temp.ty,false);
}
function 
onWeaponFired(){
  
temp.tx player.vecx(player.dir)*2+1.5;
  
temp.ty player.vecy(player.dir)*2+2// checks in front of the player does replace
  
player.chat testTiles(temp.tx,temp.ty,true);


This one is the class.
PHP Code:

//NPC Created by Rogue Shadow (TCN)

//#CLIENTSIDE
function InitializeTiles(){
  
this.TileObjects = {};    //       Name,      Tiles to Find,             Tiles to Replace with
  
this.TileObjects.add(newTileObject("Bush", {{2,3},{18,19}} , {{0x2A5,0x2A6},{0x2B5,0x2B6}} ));
  
this.TileObjects.add(newTileObject("Swamp", {{ 420421},{436 ,437 }} , {{679680},{695 ,696 }} ));
  
this.TileObjects.add(newTileObject("Vase", {{684,685},{700,701}} , {{1770,1771},{1786,1787}} ));
  
this.TileObjects.add(newTileObject("Stone", {{34,35},{50,51}} , {{1834,1835},{1850,1851}} ));
  
this.TileObjects.add(newTileObject("BlackStone", {{990,991},{1006,1007}},{{1834,1835},{1850,1851}} ));
  
this.TileObjects.add(newTileObject("Sign", {{512,513},{528,529}} , {{1802,1803},{1818,1819}} ));
  
this.TileObjects.add(newTileObject("Post", {{1652,1653},{1668,1669}}, {{1802,1803},{1818,1819}} ));
  
this.TileObjects.add(newTileObject("Grass", {{2047,2047},{2047,2047}} , {{1834,1835},{1850,1851}} ));
}
function 
newTileObject(label,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();
  return 
temp.to;
}
function 
testTiles(testx,testy,mode){//mode=true, replace tiles found, false, report name of tiles found
  
if (temp.obj == null)temp.obj this.TileObjects;
  
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]);
        return 
true;
      }else return 
temp.test[2].label;
    }
  }
  return 
false;
}
function 
checkTiles(testx,testy,obj) {
  
temp.tile tiles[temp.testx,temp.testy];
  if (
temp.obj == null)temp.obj this.TileObjects;
  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(array,obj){
  for (
temp.xytemp.array){
    for (
temp.0temp.<  temp.obj.wtemp.i++) {
      for (
temp.0temp.temp.obj.htemp.j++){
        
tiles[temp.i+temp.xy[0],temp.j+temp.xy[1]] = temp.obj.replace[temp.j][temp.i];
        
updateboard(temp.xy[0],temp.xy[1],temp.obj.w,temp.obj.h);
      }
    }
  }


If I am missing any other tiles that respawn automatically, let me know. also, I know the bigrock one doesn't.

coreys 04-09-2010 05:34 PM

Neato, could be very useful :)

adam 04-09-2010 11:56 PM

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



sssssssssss 01-12-2013 05:16 AM

I know this is older, but thank God this is here. Just saved me a buttload of time.:)


All times are GMT +2. The time now is 11:52 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.