Sign in to follow this  
Akinari

r17386: Instance System Rewrite!

Recommended Posts

Instance System Rewrite!!

 

r17386 contains a complete instance system rewrite!  In a nutshell this new instance system allows us to create instances in a much easier fashion as opposed to the 5+ steps it took before.  With the introduction of an instance database, creating an instance within a script is as simple as a single command, as well as entering it.  Everything in instance creation is now handled automatically, making scripting instances a breeze compared to before.

 

Features:

  • Separation of instances from maps and scripts

This allows us to create a system that is independent of the main functions (killmonster, monster, warp) using a new command instance_mapname();  Now whenever specifying a map for an instance, we no longer need specific commands to have these src4instance checks.  Everything related to instancing is also done on an as needed basis, which means there won't be extra processing on each script run to figure out whether you're in an instance or not.

  • Loading an instance automatically runs OnInstanceInit

Before it was an extra task taking generally 20-50 extra lines of unnecessary code.  Now, when specifying your instance to create, this is no longer an issue.

  • Instance database files hold the instances to be made

With a new database file that contains all the instances, we no longer have to manually add each instance map and attach it to the scripts.  This is another way we've made a system that works for the scripters, not making the scripters work for the system.  We've also added a useful @reload instancedb command to reload the instancedb in runtime.

  • Instances persist through @reloadscript

One of the major reasons for this rewrite was to offer us the ability to use reloadscript and keep our instances in-tact.  Now, when a reloadscript occurs, we reset all players to start of the instance and reset their timer.  Instance persistence can be expanded upon later allowing us to store these into the SQL and even recreate them on server reboots!

  • Script commands rewritten

With the new system, we've removed a set of commands.  These include:

  • instance_attachmap
  • instance_attach
  • instance_set_timeout
  • instance_init
  • instance_detachmap
  • has_instance
  • Create instance of any map

In the old system, we could only create instances of maps which were named to be instances because others would crash the client.  Now you can create an instance of any map you'd like.

 

Usage:

  • To create an instance, first add it into the new database, then you can create it using instance_create and enter the instance with instance enter:
10,Instance Prontera,7200,prontera,150,150,prontera
if (instance_create("Instance Prontera") < 0) // Check for a failure in creating instance
instance_enter("Instance Prontera");
  • To make a monster in an instance, simply use the instance_mapname function.
areamonster instance_mapname("prontera"),155,150,160,155,"Prontera Octopus",2192,3;
  • You can refer to the rewritten instance scripts for more examples. Documentation for the new commands is below.

    *instance_create("<instance name>");
     
    Creates an instance for the party of the attached player. The instance name,
    along with all other instance data, is read from 'db/(pre-)re/instance_db.txt'.
    Upon success, the command generates a unique instance ID, duplicates all listed
    maps and NPCs, sets the alive time, and triggers the "OnInstanceInit" label in
    all NPCs inside the instance.
     
    The command returns the instance ID upon success, and these values upon failure:
     -1: Invalid type.
     -2: Party not found.
     -3: Instance already exists.
     -4: No free instances (MAX_INSTANCE exceeded).
     
    ---------------------------------------
     
    *instance_enter("<instance name>");
     
    Warps player to the specified instance after the script terminates. The map and
    coordinates are located in 'db/(pre-)re/instance_db.txt'.
     
    The command returns 0 upon success, and these values upon failure:
     1: Party not found.
     2: Party does not have an instance.
     3: Other errors (invalid instance name, instance doesn't match with party).
     
    ---------------------------------------
     
    *instance_mapname("<map name>"{,<instance id>});
     
    Returns the unique name of the instanced map. If no instance ID is specified,
    the instance the script is attached to is used. If the script is not attached to
    an instance, the instance of the currently attached player's party is used. If
    that fails, the command returns an empty string instead.
     
    ---------------------------------------

 

Special Thanks:

  • Euphy for suggesting this rewrite be done, doing hours of testing, and rewriting the scripts for the new system.  It would have never been done without him.
  • Auriga the Japanese emulator for giving me a place to start as well as much of the code in the new system.  It certainly made this task much easier.
  • Lemongrass for helping me out along the way and providing some code improvements in the final stages.
  • Lighta for help in fixing bugs.

 

The Future:

 

Expect expansions upon this project such as instance storing in SQL and possibly additional instance types such as guild instancing.  Please remember to post bug reports in the proper area and if you have any questions or need help converting a script, don't hesitate to ask.

 

Commit 1

Commit 2

  • Upvote 8
  • Like 1

Share this post


Link to post
Share on other sites

Amazing work, Akinari! Hopefully we'll see some more instance scripts in the future because of this... :3

  • Upvote 1

Share this post


Link to post
Share on other sites

I always wonder how to easy make an instance,

this change is wonderfull!

 

Thanks Akinari

Share this post


Link to post
Share on other sites

Oh finally, been waiting for instance to be improved, thanks for this Akinari great work.

 

I guess i can start releasing instance scripts now~

  • Upvote 1

Share this post


Link to post
Share on other sites

I don't think this is a good work

even it could make scripts easy

but some instance script have to rewrite

I hope it can keep the old system ...

Share this post


Link to post
Share on other sites

I don't think this is a good work

even it could make scripts easy

but some instance script have to rewrite

I hope it can keep the old system ...

So you're saying you don't appreciate the hard work of the coders? It's better to rewrite some instance scripts than have them complicated for no reason. You'll be thankful when you write a new instance script.

Share this post


Link to post
Share on other sites

I don't think this is a good work

even it could make scripts easy

but some instance script have to rewrite

I hope it can keep the old system ...

 

It's definitely a good work. So much easier with the new instance system.

If you have problem rewriting it, you can ask around. 

Share this post


Link to post
Share on other sites

I don't think this is a good work

even it could make scripts easy

but some instance script have to rewrite

I hope it can keep the old system ...

So you're saying you don't appreciate the hard work of the coders? It's better to rewrite some instance scripts than have them complicated for no reason. You'll be thankful when you write a new instance script.

I didn't say that. I just hope so the coders can keep the old system.

Share this post


Link to post
Share on other sites

That would be counterproductive and pointless to keep two instancing systems around especially when the new one is much better overall and far less resource intensive than the old system.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this