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 09-15-2008, 09:48 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Gmap Generator

Script: gmap_generator.txt ( 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:
template_default.nw

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
__________________
Reply With Quote
  #2  
Old 09-15-2008, 10:09 PM
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
Good job
__________________
Reply With Quote
  #3  
Old 09-15-2008, 11:21 PM
TheStan TheStan is offline
Stan?
Join Date: May 2008
Location: U.S.
Posts: 100
TheStan is on a distinguished road
Send a message via AIM to TheStan Send a message via MSN to TheStan
rep ++
Reply With Quote
  #4  
Old 09-16-2008, 06:13 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
neat, rep++
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #5  
Old 09-16-2008, 06:19 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Very nifty
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #6  
Old 09-16-2008, 08:01 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
This is nice.

Though I would still use the offline gmap generator because the input image allows basic customization.
__________________
Reply With Quote
  #7  
Old 09-16-2008, 08:20 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
thanks everyone =D

Quote:
Originally Posted by Inverness View Post
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
__________________
Reply With Quote
  #8  
Old 07-09-2009, 05:57 PM
GULTHEX GULTHEX is offline
Registered User
Join Date: Jul 2008
Posts: 148
GULTHEX can only hope to improve
okay so you make the wepnpc

the you make the other script

wich where do we put to?

because some people might be confused
Reply With Quote
  #9  
Old 07-09-2009, 06:15 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by GULTHEX View Post
because some people might be confused
don't say people when you are talking about yourself
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #10  
Old 07-09-2009, 07:44 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
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
__________________
Reply With Quote
  #11  
Old 06-06-2012, 08:13 AM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
Quote:
Originally Posted by Deas_Voice View Post
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. :[
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz




Last edited by Devil_Lord2; 06-06-2012 at 10:10 AM..
Reply With Quote
  #12  
Old 06-06-2012, 04:21 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #13  
Old 06-06-2012, 11:09 PM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
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!
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz



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


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