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 05-15-2011, 11:06 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
Instance Manager

This is something I originally wrote for Kingdoms iPhone, which has since been used and tested on Graal Kingdoms for the Easter event. It allows you to create clones ("instances") of a level (or set of levels).

Example usage: You have a quest which can be completed by groups of three players. Each group of three players needs their own private set of levels so that other players don't interfere with their quest. This script will clone the levels and take care of changing links, as well as deleting the levels after you're done with them.

An example of creating an instance:

Graal Script Code:
temp.instance = new EasterMapInstance();
temp.instance.data.owner temp.owner;
temp.instance.prepare(); 
When you create an instance, it does a couple things:
  • Copies all the files you specify to a temporary folder.
  • For each GMAP specified, it copies all the levels and changes all the links inside them. The GMAP is also loaded via addgmap.
  • For each level specified, if links inside the level point to a level which is being copied, those links will be updated to point to that level inside the instance. If the links link outside the instance, they are left alone.
  • For each level, a small NPC is inserted which sets level.instance to the instance object. This makes it easy for scripts to interact with the instance.

Creating a new instance type involves adding the following to the main InstanceManager NPC:

Graal Script Code:
// Easter Maps
EasterMapInstance newInstanceTemplate("GameInstance");
EasterMapInstance.join("easter2k11_instance_map"); 
You then need to create the class which controls the instance. A simplified example from the Easter event:

Graal Script Code:
// class "easter2k11_instance_map"
public function prepare() {
  
// choose a random map
  
this.mapLevelName EasterMapControl.getRandomMapName();
  
  
temp.resources = {
    
"levels/world/events/easter2k11/maps/" realMapLocation
  
};
  
  
this.setResources(resources); // set which resources are needed
  
this.initResources(); // make a copy of those resources
  
  // close after 10 minutes
  
this.scheduleEvent(600"onCloseInstance");
  
  
// start the timeout
  
this.trigger("timeout");
}

public function 
enterPlayer(temp.pl) {
  
// this.getResourceName(resourceName) accepts the original name
  // and returns the name of the instance-specific resource
  
temp.pl.setLevel2(this.getResourceName(this.mapLevelName), 3232);
}

function 
onCloseInstance() {
  
// time ran out; you'll probably want to warp players out first,
  // although it will handle it for you if you don't
  
this.closeInstance();
}

function 
onTimeOut() {
  if (
this.data.owner == null || this.data.owner.level.instance != this) { // the owner logged out or left the instance
    
this.closeInstance();
  }
  
  
this.setTimer(10);

As you can see, it handles all of the hard stuff (like changing links and copying files) for you. It also deletes the temporary files when the instance is closed. Make sure to close the instance or you will essentially have created a memory leak, and you will also litter the folder with files.

One thing to note is if you are creating GMAPs, it will add them to gmaps= in server options. There is currently no way to remove them except for manually, so it will crowd server options very fast. There is no negative effect on the server that I am aware of—Kingdoms was running fine with at least 300 maps in gmaps=—but you will want to remove them periodically. If Stefan adds a way to remove them dynamically, I will update this script.

It should be able to copy any kind of GMAP (including ones generated with the terrain generator or dungeon generator).

Setup
To get started, you first need to give (npcserver) rights to a location for files to be stored (be sure they're also in folder config). You can change these rights to suit your preferences:
Quote:
rw levels/temp/*.nw
rw levels/temp/*.gmap
You must also give it read rights to the location where you store the files to be copied.

Quote:
r levels/world/quests/*.nw
Then, upload the scripts in the attached archive. Change the settings in InstanceManager to suit your server's temp path and unstick location (called "emergency exit" since it's where players are kicked to if you close the instance without warping them out).

To add more instances, just modify the Easter example which I left commented out.

If you have any questions or if I left anything out just post here and I'll be happy to help .
Attached Files
File Type: zip instance.zip (5.9 KB, 186 views)
__________________
Reply With Quote
  #2  
Old 05-16-2011, 12:39 AM
Seich Seich is offline
Noctorious' NeoHunter
Seich's Avatar
Join Date: Jun 2008
Location: Honduras
Posts: 193
Seich will become famous soon enough
Send a message via MSN to Seich Send a message via Yahoo to Seich Send a message via Skype™ to Seich
That's really nice Great job.
Reply With Quote
  #3  
Old 05-16-2011, 03:01 AM
MattKan MattKan is offline
the KattMan
Join Date: Aug 2010
Location: United States
Posts: 1,325
MattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to behold
Send a message via AIM to MattKan Send a message via Skype™ to MattKan
You're so divine.
__________________
Quote:
Originally Posted by Satoru Iwata
On the other hand, free-to-play games, if unbalanced, could result in some consumers paying extremely large amounts of money, and we can certainly not expect to build a good relationship with our consumers in this fashion. In order to have a favorable long-term relationship, we would like to offer free-to-play games that are balanced and reasonable.
Quote:
Originally Posted by Unximad
Eurocenter Games remains attached to the values of indies game developer and to the service our playerbase community.
Reply With Quote
  #4  
Old 05-16-2011, 04:51 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Good work, definitely will be useful considering where Graal is moving.
Reply With Quote
  #5  
Old 05-16-2011, 10:17 AM
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
I'll most likely be using this later on. Thanks!
__________________
Reply With Quote
  #6  
Old 07-22-2011, 06:55 PM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
I'm not exactly sure who it was, maybe Ziro...but I recall seeing someone use a method similar to this to create a turn-based battle system. Now that I think about it it was DEFINITELY Ziro...in any event do you think it's necessary to use objects with this? Eventually there will be a lot of objects around at one point or another.

Edit: Although they'll be temporary.

Edit 2: In any event great work.
__________________
Stan.
Reply With Quote
  #7  
Old 07-22-2011, 08:53 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
Quote:
Originally Posted by Kyranki View Post
I'm not exactly sure who it was, maybe Ziro...but I recall seeing someone use a method similar to this to create a turn-based battle system. Now that I think about it it was DEFINITELY Ziro...in any event do you think it's necessary to use objects with this? Eventually there will be a lot of objects around at one point or another.
There will only be as many objects as there are existing instances at the moment. Objects give you far more versatility than you'd have if you were doing it any other way.
__________________
Reply With Quote
  #8  
Old 07-23-2011, 06:57 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
Quote:
Originally Posted by cbk1994 View Post
There will only be as many objects as there are existing instances at the moment. Objects give you far more versatility than you'd have if you were doing it any other way.
That's exactly the issue, say for example there are 100 players online, and they ALL go to a single player dungeon, the exact same one...though not highly likely it could still cause ridiculous cp strain. Just saying tho.

I see the funtionality possible using objects, I think this should have a broader use though considering the use of objects.
__________________
Stan.
Reply With Quote
  #9  
Old 07-23-2011, 07:13 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
Quote:
Originally Posted by Kyranki View Post
That's exactly the issue, say for example there are 100 players online, and they ALL go to a single player dungeon, the exact same one...though not highly likely it could still cause ridiculous cp strain. Just saying tho.

I see the funtionality possible using objects, I think this should have a broader use though considering the use of objects.
100 objects is not going to cause strain on the server unless you're copying a huge number of levels inside of those instances or you're doing something intensive inside those objects' classes.
__________________
Reply With Quote
  #10  
Old 06-12-2012, 08:54 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
I'm not sure why when I type in "Instance System" or "Instance Manager" I can never find this thread.. That or even looking in the Code Gallery which this thread is said to be in...

Anyway, the problem is... well I don't know...
Cujo started the process, we have a class called "instance" and a class called "intro_instance_map". a

Then inside our NPCs we have InstanceManager.

Inside Folderconfig
level temp/*.graal
level temp/*.nw
level temp/*.gmap
file temp/*.gmap

Inside NPC Server:
r levels/0intro/*
rw levels/temp/*.nw

We both aren't sure what is supposed to happen next, but we do know for the most part that it is not working. This is something we would absolutely love to have for the intro, but he and I cannot seem to figure it out. I just checked today, the whole thing is confusing. The only thing it seemed like I had to do that it did not look like he did was add the rights to the NPC server..

Not sure what type of details are needed..

// class "easter2k11_instance_map"
public function prepare() {
// choose a random map
this.mapLevelName = IntroMapControl.getRandomMapName();

temp.resources = {
"levels/0intro/" @ realMapLocation
};


function onCreated() {
// basic setup
GameInstance = newInstanceTemplate("TStaticVar");
GameInstance.setTempPath("levels/temp/"); // folder which holds resources
GameInstance.setEmergencyExit("shaded_p09.nw", 30, 30);

IntroMapInstance = newInstanceTemplate("GameInstance");
IntroMapInstance.setTempPath("levels/intro0/");
IntroMapInstance.join("intro_instance_map");
}

He joined the class in basically all the levels.. It doesn't use a gmap.. I don't know ...
Can anyone help?
__________________

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



Reply With Quote
  #11  
Old 06-12-2012, 09:23 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
Quote:
Originally Posted by Devil_Lord2 View Post
I'm not sure why when I type in "Instance System" or "Instance Manager" I can never find this thread.. That or even looking in the Code Gallery which this thread is said to be in...
You sure seem to have a lot of trouble with search engines.




Quote:
Anyway, the problem is... well I don't know...
Cujo started the process, we have a class called "instance" and a class called "intro_instance_map". a

Then inside our NPCs we have InstanceManager.

Inside Folderconfig
level temp/*.graal
level temp/*.nw
level temp/*.gmap
file temp/*.gmap

Inside NPC Server:
r levels/0intro/*
rw levels/temp/*.nw

We both aren't sure what is supposed to happen next, but we do know for the most part that it is not working. This is something we would absolutely love to have for the intro, but he and I cannot seem to figure it out. I just checked today, the whole thing is confusing. The only thing it seemed like I had to do that it did not look like he did was add the rights to the NPC server..

Not sure what type of details are needed..

Graal Script Code:
// class "easter2k11_instance_map"
public function prepare() {
  
// choose a random map
  
this.mapLevelName IntroMapControl.getRandomMapName();
  
  
temp.resources = {
    
"levels/0intro/" realMapLocation
  
}; 

Graal Script Code:
function onCreated() {
  
// basic setup
  
GameInstance newInstanceTemplate("TStaticVar");
  
GameInstance.setTempPath("levels/temp/"); // folder which holds resources
  
GameInstance.setEmergencyExit("shaded_p09.nw"3030);
  
  
IntroMapInstance newInstanceTemplate("GameInstance");
  
IntroMapInstance.setTempPath("levels/intro0/");
  
IntroMapInstance.join("intro_instance_map");

He joined the class in basically all the levels.. It doesn't use a gmap.. I don't know ...
Can anyone help?
It seems like this script is going over your heads. The class does not need to be joined in any levels. The main NPC will handle that. See how I did the easter map and then modify that to suit your needs (copy the appropriate levels).

Also see how I created new instances. All of that information is in the OP.
__________________
Reply With Quote
  #12  
Old 06-12-2012, 05:02 PM
MattKan MattKan is offline
the KattMan
Join Date: Aug 2010
Location: United States
Posts: 1,325
MattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to behold
Send a message via AIM to MattKan Send a message via Skype™ to MattKan
Quote:
Originally Posted by cbk1994 View Post
You sure seem to have a lot of trouble with search engines.



I seem to remember something like this happening before...
Reply With Quote
  #13  
Old 06-12-2012, 06:28 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 had no reason to use Google since I knew the instance manager is on this forums, as well as I only type in the name "Instance Manager" and "Instance System" since... well that is the name.

Oddly enough now that I've brought it back, or 'bumped' the post, it shows up, previously, I had to search for your name, view your profile, statistics, and any threads by you. I am well aware how to use a search system. But you are correct, compared to Graal Forums, and Wiki, obviously Google is better organized, and better to use for searching which is why I should have used it. I've had a class both in high school, and college teaching about key words, and searching through a search system.

Now, since I'm trying to get help, and not argue, lets just say we have tried again, still not working...

Do you, or anyone, mind actually trying to help?
It would be better off to leave out statements like "Check wiki"..

Sure, not many people may need this system, and step-by-step instructions probably aren't asked for due to this fact, however, we find what you've done to be something that could be useful. Whereas we could work around this and do the old style of putting people in a wait room, we would appreciate it if someone could give instructions instead of hoping we can look at the first post and inside the program to understand.

(Point is, not many people might need this, and those that do and don't have any programming experience may not understand any of this since the first post doesn't exactly explain much but what to add...)
Attached Thumbnails
Click image for larger version

Name:	Screen shot 2012-06-12 at 11.14.31 AM.png
Views:	143
Size:	134.2 KB
ID:	54832   Click image for larger version

Name:	Screen shot 2012-06-12 at 11.16.01 AM.png
Views:	125
Size:	148.9 KB
ID:	54834   Click image for larger version

Name:	Screen shot 2012-06-12 at 11.16.54 AM.png
Views:	128
Size:	295.2 KB
ID:	54835  
__________________

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



Reply With Quote
  #14  
Old 06-12-2012, 08:45 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
I already explained what you need to do in my previous post. Did you ignore the bottom half? This isn't just a copy-and-paste system, but it's not difficult to use if you read the OP.
__________________
Reply With Quote
  #15  
Old 06-13-2012, 04:00 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
pretty sure the forum search orders by the most recent post by default, and doesn't order by relevancy unless you tell it to. I'm guessing the keyword "manager" has probably been used a lot since the creation of this thread, which is why you couldn't find it until now.
__________________
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 10:49 PM.


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