Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Gmap Generator (https://forums.graalonline.com/forums/showthread.php?t=81853)

Chompy 09-15-2008 09:48 PM

Gmap Generator
 
2 Attachment(s)
Script: Attachment 45896 ( Stupid percent symbols D: )

Basically lets you create a gmap with any dimension wanted (Not sure though, because of the maxlooplimit).

Anyways, to the point, or.., to the examples! Let's say we named the wnpc GmapGenerator or something.

PHP Code:

function onCreated() {
  
GmapGenerator.createGmap("testgmap", {44});


This would create one testgmap.gmap file and 16 testgmap_*.nw files in the directory told in the 'this.savepath' variable in the onCreated() event.

Now, how can I get these gmaps to work online? :O!?!?!?!?!?!

Some steps:

1) Move all the files that were generated (.gmap and .nw files) into levels/ or somwhere levels are downloadable.
2) Go into server options and look for "gmaps=". There you simply put the filename of the (.gmap) file (without the .gmap ending).
(For example, gmaps=testgmap,)
3) Add this line to a script that the player(s) have clientside: loadmap(gmapname);, and again, the name of the (.gmap) file without the .gmap ending (Example: loadmap("testgmap");) (Only do this if necessary)
4) Say this in rc chat: /updatelevel gmapname.gmap (Example: /updatelevel testgmap.gmap)
5) Now you can warp to your gmap.
6) If it is not working, get someone to restart the gserver.
7) Still not working? Start over.


-----

More examples:

PHP Code:

function onCreated() {
  
GmapGenerator.createGmap("testgmap""sqrt16"); // 4x4 gmap
  
  
GmapGenerator.createGmap("testgmap"5); // 5x5 gmap
 
  
GmapGenerator.createGmap("testgmap", {43}); // 4x3 gmap


----

If you want a script to be added to all the generated levels, add it to the template level =)


----

Suggestions on how to improve are welcome, and please post bugs if found =)

Also, here's the template level I used:
Attachment 45895

For some reason plain boards (Boards with only AA (upper left grass tile) tiles) aren't saved to the .nw file.

Edit: I just noticed I did all the link detection in a rather.. repetive and odd way.. next update will be a rewrite of the links :o

cbk1994 09-15-2008 10:09 PM

Good job :)

TheStan 09-15-2008 11:21 PM

rep ++

Deas_Voice 09-16-2008 06:13 PM

neat, rep++

Tigairius 09-16-2008 06:19 PM

Very nifty :)

Inverness 09-16-2008 08:01 PM

This is nice.

Though I would still use the offline gmap generator because the input image allows basic customization.

Chompy 09-16-2008 08:20 PM

thanks everyone =D

Quote:

Originally Posted by Inverness (Post 1423996)
Though I would still use the offline gmap generator because the input image allows basic customization.

Indeed, I could probably make some detection looping through each pixel on the image detecting the RGB, but, too bad I don't have enough freetime for that xD

GULTHEX 07-09-2009 05:57 PM

okay so you make the wepnpc

the you make the other script

wich where do we put to?

because some people might be confused

Deas_Voice 07-09-2009 06:15 PM

Quote:

Originally Posted by GULTHEX (Post 1505552)
because some people might be confused

don't say people when you are talking about yourself :)

Crow 07-09-2009 07:44 PM

Not bad. May I suggest a feature though? I didn't look through the whole code, but it seemed you are copying the naming format of the standalone generator. I suggest changing the format and adding two more parameters, center x and center y, so the map can be extended in every direction at any time easily, just like you can do it with my generator :p

Devil_Lord2 06-06-2012 08:13 AM

Quote:

Originally Posted by Deas_Voice (Post 1505555)
don't say people when you are talking about yourself :)

I'm pretty confused.
Just because you get it as well as other programmers does not mean everyone without knowledge in the field will.
There is no reason to put him down.

I won't ask here however, eventually I'll find a tutorial that is helpful.

PHP Code:

function onCreated() {
  
GmapGenerator.createGmap("nalik_caverns", {44});
  
this.template "levels/nalik_caves.nw"// "levels/template_default.nw";
  
this.savepath "levels/nalik_caverns/"// "levels/";

  /* DON'T EDIT ANYTHING BELOW HERE =) */
  
this.ALPHABET = {
    
"a""b""c""d""e",
    
"f""g""h""i""j",
    
"k""l""m""n""o",
    
"p""q""r""s""t",
    
"u""v""w""x""y""z"
  
};
}
public function 
createGmap(prefixdimension) {
  
temp.type dimension.type();
  if (
type != 3) {
    if (
type == 1) {
      if (
dimension.starts("sqrt")) {
        
temp.float(dimension.substring(4));
        
int(n^0.5);
        
dimension = {n,n};
      }
      else return 
false;
    }
    else if (
type == 0) {
      
dimension = {int(dimension), int(dimension)};
    }
  }
  else {
    
dimension = {int(dimension[0]), int(dimension[1])};
  }
  
temp.gmap = {
    
"GRMAP001",
    
"WIDTH "dimension[0],
    
"HEIGHT "dimension[1],
    
"LEVELNAMES"
  
};

  
this.numbers dimension[1].length();
  
this.letters int(dimension[0]/26);
  
temp.levels 0;
  for(
temp.0dimension[1]; ++) {
    
temp.line "";
    for(
temp.0dimension[0]; ++) {
      
temp.data = {getletter(j), getnumber(i+1)};
      
line @= stringify(prefix "_" data[0] @ data[1] @ ".nw") @",";
      
levels.add({(data[0]@data[1]), ji});
    }
    
gmap.add(line.substring(0line.length()-1));
  }
  
gmap.add("LEVELNAMESEND");

  
gmap.savelines(this.savepath@prefix@".gmap"0);

  
// lets generate the levels for the gmap

  
temp._template.loadlines(this.template);
  
this.maxlooplimit 0x7fffffff// =) we do want bigger gmaps then 100x100

  
for(temp.lvl levels) {
    
temp.links findlinks(prefixlvldimension);
    for(
temp.links) {
      
_template.add(l);
    }

    
_template.savelines(this.savepath@prefix@"_"@lvl[0]@".nw"0);
    
_template _template.subarray(0_template.size()-links.size());
  }
}

function 
getletter(n) {
  
temp.this.letters;
  
temp.times 0;
  while(
0) { times ++; --; }
  
temp.out "";
  
int(n);
  for(
temp.times0--) {
    
temp.index n;
    for(
temp.0i++) {
      
index /= 26;
    }
    
index int(index);
    
out @= this.ALPHABET[index];
  }
  
out @= this.ALPHABET[n%26];
  return 
out;
}

function 
getnumber(n) {
  
temp.n;
  while(
i.length() < this.numbers) {
    
"0"@i;
  }
  return 
i;
}

function 
stringify(foo) {
  return 
"\"" foo "\"";
}

function 
findlinks(prefixmatrixdimension) {
  
temp.lvl matrix;
  
temp.out 0;
  if (
lvl[1] == 0) {
    if (
lvl[2]+== 1) {
      
out.add("LINK "@prefix@"_"@getletter(lvl[1]+1)@getnumber(lvl[2]+1)@".nw 63 0 1 64 0 playery");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1])@getnumber(lvl[2]+2)@".nw 0 63 64 1 playerx 0");
    }
    else if (
lvl[2]+== dimension[1]) {
      
out.add("LINK "@prefix@"_"@getletter(lvl[1]+1)@getnumber(lvl[2]+1)@".nw 63 0 1 64 0 playery");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1])@getnumber(lvl[2])@".nw 0 0 64 1 playerx 61");
    }
    else {
      
out.add("LINK "@prefix@"_"@getletter(lvl[1]+1)@getnumber(lvl[2]+1)@".nw 63 0 1 64 0 playery");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1])@getnumber(lvl[2])@".nw 0 0 64 1 playerx 61");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1])@getnumber(lvl[2]+2)@".nw 0 63 64 1 playerx 0");
    }
  }
  else if (
lvl[1] == dimension[0]-1) {
    if (
lvl[2]+== 1) {
      
out.add("LINK "@prefix@"_"@getletter(lvl[1]-1)@getnumber(lvl[2]+1)@".nw 0 0 1 64 61 playery");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1])@getnumber(lvl[2]+2)@".nw 0 63 64 1 playerx 0");
    }
    else if (
lvl[2]+== dimension[1]) {
      
out.add("LINK "@prefix@"_"@getletter(lvl[1]-1)@getnumber(lvl[2]+1)@".nw 0 0 1 64 61 playery");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1])@getnumber(lvl[2])@".nw 0 0 64 1 playerx 61");
    }
    else {
      
out.add("LINK "@prefix@"_"@getletter(lvl[1]-1)@getnumber(lvl[2]+1)@".nw 0 0 1 64 61 playery");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1])@getnumber(lvl[2])@".nw 0 0 64 1 playerx 61");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1])@getnumber(lvl[2]+2)@".nw 0 63 64 1 playerx 0");
    }
  }
  else {
    if (
lvl[2]+== 1) {
      
out.add("LINK "@prefix@"_"@getletter(lvl[1]-1)@getnumber(lvl[2]+1)@".nw 0 0 1 64 61 playery");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1]+1)@getnumber(lvl[2]+1)@".nw 63 0 1 64 0 playery");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1])@getnumber(lvl[2]+2)@".nw 0 63 64 1 playerx 0");
    }
    else if (
lvl[2]+== dimension[1]) {
      
out.add("LINK "@prefix@"_"@getletter(lvl[1]-1)@getnumber(lvl[2]+1)@".nw 0 0 1 64 61 playery");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1]+1)@getnumber(lvl[2]+1)@".nw 63 0 1 64 0 playery");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1])@getnumber(lvl[2])@".nw 0 0 64 1 playerx 61");
    }
    else {
      
out.add("LINK "@prefix@"_"@getletter(lvl[1]-1)@getnumber(lvl[2]+1)@".nw 0 0 1 64 61 playery");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1]+1)@getnumber(lvl[2]+1)@".nw 63 0 1 64 0 playery");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1])@getnumber(lvl[2])@".nw 0 0 64 1 playerx 61");
      
out.add("LINK "@prefix@"_"@getletter(lvl[1])@getnumber(lvl[2]+2)@".nw 0 63 64 1 playerx 0");
    }
  }
  return 
out;


Three year bump? Yes I did, negative rep me. ;D


-EDIT-
Actually it doesn't seem possible for a Mac user to do this...
.exes... youtube videos talking about the level editor.. its all a bunch of voodoo
witchcraft us cool cats can't use or something. :[

fowlplay4 06-06-2012 04:21 PM

Tip: Make it more clear that you are having an issue with the script and need help otherwise your post just looks like spam.

Remove "GmapGenerator." (or replace it with this.) at the top there, since the function is in your script.

Your (npcserver) should also have the following in it's folder rights:

r levels/nalik_caves.nw
rw levels/nalik_caverns/*.gmap
rw levels/nalik_caverns/*.nw

After applying the script it should work fine provided the script isn't broken.

Devil_Lord2 06-06-2012 11:09 PM

I don't know, I thought I said I put it in a level npc online.. but since I don't know exactly what I was supposed to do I can't say if it was right or wrong.. only that it did not work. Then I tried to do more research on it...

I know in server options we already had gmap= type things so I did add that.. As well as the level, folder, ganis, txt, .graal and .nw rights too... (why do we still add .graal?)

Anyway, Cbk sent me this link http://www.graal.us/tools/generatelevels.html which has helped amazingly and exactly what I needed. (I suppose it works in this thread in case others see it and only want something simple.)

From the starting post, it just seemed like you add in all the text from the script, edit the first part, then stick in the other thing under onCreated and it would do the rest for you.. Maybe it is like that and somehow I did it wrong, or maybe I did it wrong entirely.. Although eventually I got the solution by link. o.O;;

Thank you though!


All times are GMT +2. The time now is 12:58 AM.

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