Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Instance Manager (https://forums.graalonline.com/forums/showthread.php?t=134263240)

cbk1994 05-15-2011 10:06 PM

Instance Manager
 
1 Attachment(s)
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:

PHP 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:

PHP 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:

PHP 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 :).

Seich 05-15-2011 11:39 PM

That's really nice ^^ Great job.

MattKan 05-16-2011 02:01 AM

You're so divine.

WhiteDragon 05-16-2011 03:51 AM

Good work, definitely will be useful considering where Graal is moving.

Crow 05-16-2011 09:17 AM

I'll most likely be using this later on. Thanks!

Kyranki 07-22-2011 05:55 PM

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.

cbk1994 07-22-2011 07:53 PM

Quote:

Originally Posted by Kyranki (Post 1659823)
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.

Kyranki 07-23-2011 05:57 AM

Quote:

Originally Posted by cbk1994 (Post 1659839)
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.

cbk1994 07-23-2011 06:13 AM

Quote:

Originally Posted by Kyranki (Post 1659946)
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.

Devil_Lord2 06-12-2012 07:54 AM

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?

cbk1994 06-12-2012 08:23 AM

Quote:

Originally Posted by Devil_Lord2 (Post 1697050)
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.

http://uploads.graalcenter.org/uploa...17.09%20AM.png
http://uploads.graalcenter.org/uploa...18.06%20AM.png

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..

PHP Code:

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


PHP 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.

MattKan 06-12-2012 04:02 PM

I seem to remember something like this happening before... :noob:

Devil_Lord2 06-12-2012 05:28 PM

3 Attachment(s)
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...)

cbk1994 06-12-2012 07:45 PM

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.

salesman 06-13-2012 03:00 AM

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.


All times are GMT +2. The time now is 01:23 PM.

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