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 04-09-2010, 02:41 AM
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
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...

Graal Script 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.
Graal Script 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.
__________________
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-09-2010 at 03:08 PM..
Reply With Quote
  #2  
Old 04-09-2010, 06:34 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Neato, could be very useful
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #3  
Old 04-10-2010, 12:56 AM
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()


Graal Script 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:
Graal Script 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.

Graal Script 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 08:24 AM..
Reply With Quote
  #4  
Old 01-12-2013, 05:16 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Send a message via Skype™ to sssssssssss
I know this is older, but thank God this is here. Just saved me a buttload of time.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


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:31 AM.


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