NPC Script Engine

07/17/2011 22:03 BaussHacker#1
It's all made by me and it's just using delegates and reading files. I know it's not the best way etc. I just thought I would share it anyway, if anybody was interested in using it.

There is 2 downloads, one for the source code, if anybody is interesting in customizing it or whatever and then one for the library, which you just add to your project.

How can you use this?

Make a new class in your project, which is where you will handle it.
Use this as a reference or convert it to your own. (Not all functions and handlers are included and only examples are given.)
PHP Code:
public class ConquerScripting
    
{
        public static 
ScriptEngine NPCEngine = new ScriptEngine(Environment.CurrentDirectory + @"\NPCs");
        public static 
void Create()
        {
            
NPCEngine.TalkEvent = new ScriptEventDialog(Talk);
            
NPCEngine.OptionEvent = new ScriptEventDialog(Option);
            
NPCEngine.EndAndAvatarEvent = new ScriptEventDialog(End);
            
NPCEngine.NotRequirementsEvent = new ScriptEventDialog(NotRequirements);
        }
        static 
void Talk(object senderobject value)
        {
            
GameClient Client sender as GameClient;
            
Client.SendNPCDialog(value.ToString());
        }
        static 
void Option(object senderobject value)
        {
            
GameClient Client sender as GameClient;
            
string[] arg value.ToString().Split(':');
            
NPCEngine.HandleNPC(ClientNPCIDbyte.Parse(arg[0]), Client.ScriptClient);
        }
        static 
void End(object senderobject value)
        {
            
GameClient Client sender as GameClient;
            
Client.SendNPCEnd((byte)value);
        }
        static 
void NotRequirements(object senderobject value)
        {
            
GameClient Client sender as GameClient;
            
Client.SendNPCDialog(value.ToString());
        }
        public static 
void ProcessScript(GameClient Clientint NPCIDbyte OptionID)
        {
            
NPCEngine.HandleNPC(ClientNPCIDOptionIDClient.ScriptClient);
        }
    } 
How does the scripting works?
Well I would suggest you take a look at the source or the example given in the download.

When you make a NPC, then it need a folder, where the options are in.

That means if you want a dialog for ex. a NPC with the ID 10000, then you make a folder with the name 10000. Every text file in there is the options and the name must match the option id. Ex. for option 1 it must be 1.txt.

Then I will explain the syntax a bit.

Every dialog must start with arguments, which is where the requirements are put.
If you don't want any requirements, then you write [ARG /].

If you then want to put arguments, then it needs to look like this:
Code:
[ARG]
requirements should be here.
[/ARG]
Example:
Code:
[ARG]
ReqMoney 100
[/ARG]
A dialog is split by :, that means every argument is between the :'s in the script.

Example:
Code:
Option:255:I See.
It will first check the first argument, which is Option in this case. That way the engine knows it's an option and it will then seek and option ID for the next handler.

Comments in the NPCScripts can also be used, it's just // like in C#. But it has to be after the requirements.

Example on 2 dialogs:
Option 0:

Option 1:


I don't think there is much more to explain as I don't want to explain all the functions etc. and how it works.

Oh and a last thing, you must make a new variable for your client, with the script engine client. Make sure you use get/set, so it always updates the script engine client.

Download (Source):
[Only registered and activated users can see links. Click Here To Register...]

Download (DLL):
[Only registered and activated users can see links. Click Here To Register...]

Good luck. :D

PS: About options, you could parse it in the engine instead. One thing I just thought about.
07/17/2011 22:10 _DreadNought_#2
Sexy bro.

The syntax isnt my fav but... Nice work <3
07/18/2011 01:08 BaussHacker#3
Quote:
Originally Posted by Y u k i View Post
Ur so much better wif c# now :) IM SO FUCKING PROUD OF YOU! I HAZ TEARS IN MY EYES RIGHT NOW!
@the haters: YES IM SERIOUS!
Thank you master.

<3 :handsdown:
07/18/2011 01:38 12tails#4
;P nice work bro ^^
07/18/2011 02:27 _tao4229_#5
[Only registered and activated users can see links. Click Here To Register...]