http://wiki.graal.us/
|
 |
Join Date: Nov 2001
Posts: 2,247
|
|
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.x + vecx(player.dir)*2+1.5; temp.ty = player.y + 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", {{ 420, 421},{436 ,437 }} , {{679, 680},{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.w = temp.to.tiles[0].size(); temp.to.h = 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.o: temp.obj){ for (temp.i = 0; temp.i < temp.o.w; temp.i++ ){ for (temp.j = 0; temp.j < temp.o.h; temp.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.i = 0; temp.i < temp.obj.w; temp.i++){ for (temp.j = 0; temp.j < temp.obj.h; temp.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.xy: temp.array){ for (temp.i = 0; temp.i < temp.obj.w; temp.i++) { for (temp.j = 0; temp.j < temp.obj.h; temp.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 02:08 PM..
|