Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-21-2010, 08:30 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Level Tiling Fixer

Many servers use tiles that are supposed to be used in a block pattern, but often are destroyed by levelers who don't pay attention to such things. This script fixes it.

It turns this:



into this:



I find it most useful on grass. It works on individual levels or GMAPs.

Note that you may have to download and reupload the levels because updateBoard2 doesn't always change the file modification time, which can result in old levels being shown for some players.

Example usage:
PHP Code:
FloodFiller.fill("my_map.gmap""water");

// or

FloodFiller.fillMultiple("mylevel.nw", {"water""road""grass"}); 
PHP Code:
// DBNPC FloodFiller
function onCreated() {
  
// pattern to fill; lay it out in rows
  
this.pattern.grass.pattern = {
                                {
102410251026102710281029},
                                {
104010411042104310441045},
                                {
105610571058105910601061},
                                {
107210731074107510761077},
                                {
108810891090109110921093},
                                {
110411051106110711081109}
                              };
  
  
// tiles to fill even if not in pattern
  //   (for filling blank levels with grass, etc)
  
this.pattern.grass.exceptions = {0};
  
  
  
  
// pattern to fill; lay it out in rows
  
this.pattern.water.pattern = {
                                 {
6465},
                                 {
8081}
                               };
  
  
// tiles to fill even if not in pattern
  //   (for filling blank levels with grass, etc)
  
this.pattern.water.exceptions = {};
}

public function 
floodMultiple(levelNamepatternNames) {
  for (
temp.patternName patternNames) {
    
flood(levelNamepatternName);
    
sleep(0.1);
  }
}

public function 
flood(levelNamepatternName) {
  
temp.floodLevel findLevel(levelName);
  
  if (
floodLevel == null) {
    return echo(
"Level Flood: Level '" levelName "' not found!");
  }
  
  
temp.pattern this.pattern.(@ patternName).pattern;
  
temp.exceptions this.pattern.(@ patternName).exceptions;
  
  if (
pattern == null) {
    return echo(
"Level Flood: Pattern '" patternName "' has no defined pattern!");
  }
  
  
this.maxlooplimit 100000// 100,000
  
sleep(0.1); // make the max loop limit take effect
  
  
this.loopCount 0;
  
  
temp.possibleTiles exceptions;
  
  for (
temp.row pattern) {
    for (
temp.tile row) {
      
possibleTiles.add(tile);
      
this.nextLoop();
    }
    
    
this.nextLoop();
  }
  
  for (
temp.0floodLevel.width++) {
    for (
temp.0floodLevel.height++) {
      for (
temp.layer floodLevel.tilelayers) {
        
temp.tile layer.tiles[xy];
        
        if (
tile in possibleTiles) {
          
// replace tile
          
          
temp.row pattern[row.size()];
          
layer.tiles[xy] = row[row.size()];
        }
        
        
this.nextLoop();
      }
      
      
this.nextLoop();
    }
    
    
this.nextLoop();
  }
  
  
floodLevel.updateBoard2(00floodLevel.widthfloodLevel.height);
  
  echo(
"Level Flood: Successfully applied pattern '" patternName "' to level '" floodLevel.name "'!");
}

// increase number of loops; do I need to wait?
function nextLoop() {
  
this.loopCount ++;
  
  if (
this.loopCount >= this.maxlooplimit 1) {
    
this.loopCount 0;
    echo(
"Level Flood: Working...");
    
sleep(0.1);
  }

It should work fine with layers (it checks each layer individually for tiles that need to be replaced), but I haven't tested it.

It might be a good idea to back the levels up first since I haven't tested this in some situations.
__________________
Reply With Quote
  #2  
Old 03-21-2010, 12:05 PM
Clockwork Clockwork is offline
ᶘ ᵒᴥᵒᶅ...ᶘ ಠᴥಠᶅ❤...ℳℴℯ
Clockwork's Avatar
Join Date: Feb 2007
Location: Pennsylvania
Posts: 2,071
Clockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant futureClockwork has a brilliant future
"You must spread repuation before...."



Very nice chris.
Reply With Quote
  #3  
Old 03-21-2010, 02:48 PM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 20,000
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
Cool, should be useful for servers that use grass/water tiles that are bigger than 1x1. Especially Zone, that was a nightmare.
__________________
Reply With Quote
  #4  
Old 03-21-2010, 05:11 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Very useful, you got rep.
__________________
Reply With Quote
  #5  
Old 03-21-2010, 07:31 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
The water looked better before your script touched it.
Reply With Quote
  #6  
Old 03-21-2010, 08:20 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by DrakilorP2P View Post
The water looked better before your script touched it.
That's because the tiles suck
Reply With Quote
  #7  
Old 03-21-2010, 10:55 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Wow. This is incredibly useful for Valikorlia. I'll add this to my list of LAT tools, whenever I get around to scripting a container for all of them....

gj
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #8  
Old 03-24-2010, 10:31 PM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Quote:
Originally Posted by DrakilorP2P View Post
The water looked better before your script touched it.
Bad tiles or not, it was better to do it wrong.


but that is a nice script anyway. I like it.
__________________
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
Reply With Quote
Reply


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 02:02 PM.


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