[Hybrid]Shortcut npc

11/21/2010 19:22 Syst3m_W1z4rd#1
Would this work by creating npcs in hybrids source?
Code:
        public static void Avatar(GameClient Hero, byte face)
        {
            NpcProcessor.Dialog(Hero, new string[] {
                                "AVATAR " + face});
        }
        public static void Say(GameClient Hero, string MSG)
        {
            NpcProcessor.Dialog(Hero, new string[] {
                "TEXT " + MSG});
        }
        public static void Exit(GameClient Hero, string MSG)
        {
            NpcProcessor.Dialog(Hero, new string[] {
                "OPTION-1 " + MSG});
        }
        public static void Link(GameClient Hero, string MSG, byte Option)
        {
            NpcProcessor.Dialog(Hero, new string[] {
                "OPTION" + Option + " " + MSG});
        }
Code:
                case 0001:
                    {
                        switch (OptionID)
                        {
                            case 0:
                                {
                                    Avatar(Hero, 100);
                                    Say(Hero, "Hello There!");
                                    Link(Hero, "What sup?", 1);
                                    Exit(Hero, "Bye");
                                    break;
                                }
                            case 1:
                                {
                                    Avatar(Hero, 100);
                                    Say(Hero, "Not much");
                                    Exit(Hero, "Okay");
                                    break;
                                }
                        }
                        break;
                    }
11/21/2010 19:56 InfamousNoone#2
Looks like it would work conceptually anyways, why not test it?
11/21/2010 20:00 Syst3m_W1z4rd#3
I am gonna do, just need to download a client etc. dats why >.< I might do later today or tomorrow ;P

Thanks anyway :)
11/21/2010 20:42 Basser#4
You shouldn't have to pass the 'GameClient' parameter all the time.
11/21/2010 20:56 Syst3m_W1z4rd#5
Bas, how would u else define the GameClient? :D
Code:
        public static int Dialog(GameClient Hero, string[] dlg)
        {
11/21/2010 20:59 Basser#6
Quote:
Originally Posted by 1337 H4X0R View Post
Bas, how would u else define the GameClient? :D
Code:
        public static int Dialog(GameClient Hero, string[] dlg)
        {
There are thousands of ways to accomplish the same thing, but since you are trying to make things shorter, why keep passing that parameter all the time? Instead of passing it once?
11/21/2010 21:00 Syst3m_W1z4rd#7
Ahh I get it now.
Nevermind, just my stupidity ;P

Thanks :)
11/21/2010 23:25 KraHen#8
I don`t get how is this a shortcut though, I thought that those strings replaced lines of code where you send the dialog packets. If it is like this then you`re theoretically doubling the execution time of the parsing of an NPC.
11/21/2010 23:49 Syst3m_W1z4rd#9
Ya I found out to <.<
11/22/2010 06:11 InfamousNoone#10
Quote:
Originally Posted by KraHen View Post
I don`t get how is this a shortcut though, I thought that those strings replaced lines of code where you send the dialog packets. If it is like this then you`re theoretically doubling the execution time of the parsing of an NPC.
That's 'cuz I was originally going to integrate my entire scripting system into this souce but never got around to it albeit, I wanted to make things as user-friendly as possible.

Strings = user friendly,
Brackets, semi-colons, parameters are not sadly.
11/22/2010 10:11 Syst3m_W1z4rd#11
Well im sticking to the old methode :)
11/22/2010 15:07 KraHen#12
Quote:
Originally Posted by InfamousNoone View Post
That's 'cuz I was originally going to integrate my entire scripting system into this souce but never got around to it albeit, I wanted to make things as user-friendly as possible.

Strings = user friendly,
Brackets, semi-colons, parameters are not sadly.
I certainly see your point there, but scripting in games IMO should be done by someone who has at least a bit of experience in programming, thus making it similar to a language which many are familiar with has more advantages.

Just my two cents though :)
11/23/2010 21:33 InfamousNoone#13
Quote:
Originally Posted by KraHen View Post
I certainly see your point there, but scripting in games IMO should be done by someone who has at least a bit of experience in programming, thus making it similar to a language which many are familiar with has more advantages.

Just my two cents though :)
Since all my NPCs were home coded, my community pitched in with coding a lot of them, and they were done in a language everyone's familiar with.

Code:
' By: Wolf
' Npc: 10021
' Name: ArenaGuard

Imports System
Imports ConquerScriptLinker

Partial Public Class NpcEngine
    Public Shared Sub ArenaGuard()
        Dim dlg As String() = Nothing

        Select Case OptionID
            Case 0
                ReDim dlg(2)
                dlg(0) = "TEXT Hello would you like to enter the PK Arena for 50 silvers?"
                dlg(1) = "OPTION1 Yes, here you go."
                dlg(2) = "OPTION-1 No thanks."
            Case 1
                If Player.Money >= 50 Then
                    Player.Money -= 50
                    Command("@mm 1005 50 50")
                Else
                    ReDim dlg(1)
                    dlg(0) = "TEXT I'm sorry you dont have 50 silvers."
                    dlg(1) = "OPTION-1 Oh, I will go work my corner more."
                End If
        End Select

        If Not dlg Is Nothing Then
            Dialog(dlg)
        End If
    End Sub
End Class
Notice how the dialog functions are handled for you, also, no packet-knowledge is required and is internally done as required by the engine to synchronize the client as such. I'd explain the Engine setup, but it's overly complicated to explain how everything works at this time, for instance; this is jut setting it up;

Code:
        private static ScriptExtension GenerateExtension()
        {
            ScriptExtension extend = new ScriptExtension("Engine", "VB");
            extend.AddPreprocess("'#new_assembly System.Core.dll");
            extend.AddPreprocess("'#assembly " + ServerDatabase.Startup + "\\ConquerScriptLinker.dll");

            extend.AddNamespace("Imports ConquerScriptLinker");

            extend.AddVariable("Public Shared DatabasePath As String = \"" + ServerDatabase.Path + "\"");
            extend.AddVariable("Public Shared Player As INpcPlayer");
            extend.AddVariable("Public Shared NativeDialog As Func(Of INpcPlayer, String(), Int32)");
            extend.AddVariable("Public Shared NativeCommand As Func(Of INpcPlayer, String, Int32)");
            extend.AddVariable("Public Shared FindPlayerByName As Func(Of String, INpcPlayer)");
            extend.AddVariable("Public Shared FindPlayerByUID As Func(Of UInt32, INpcPlayer)");
            extend.AddVariable("Public Shared QueryDatabase As Func(Of String, String, String, String, String)");
            extend.AddVariable("Public Shared WriteDatabase As Func(Of String, String, String, String, Int32)");
            extend.AddVariable("Public Shared timeGetTime As Func(Of UInt32)");
            extend.AddVariable("Public Shared GuildPoleID As Func(Of UInt16)");
            extend.AddVariable("Public Shared FlipGate As Func(Of UInt32, Int32)");
            extend.AddVariable("Public Shared GenerateLotteryItem As Func(Of Int32, INpcItem)");

            extend.AddFunction(
                "Public Shared Sub Dialog(ByVal Dlg As String())\r\n" +
                    "\tNativeDialog(Player, Dlg)\r\n" +
                "End Sub"
            );
            extend.AddFunction(
                "Public Shared Sub Command(ByVal Cmd As String)\r\n" +
                    "\tNativeCommand(Player, Cmd)\r\n" +
                "End Sub"
            );

            extend.AddExternalClass(
                "\r\nPartial Public Class NpcEngine\r\n" +
                    "Inherits Engine\r\n" +
                    "\tPublic Shared NpcID As UInt32\r\n" +
                    "\tPublic Shared OptionID As Byte\r\n" +
                    "\tPublic Shared Input As String\r\n" +
                "End Class\r\n"
            );

            extend.AddExternalClass(
                "\r\nPartial Public Class ItemEngine\r\n" +
                    "Inherits Engine\r\n" +
                    "\tPublic Shared Item as INpcItem\r\n" +
                "End Class\r\n"
            );
            return extend;
        }
        private static void LinkScriptMethods()
        {
            Engine.RegisterGlobalVariable("Engine", "NativeDialog", new Func<INpcPlayer, string[], int>(Dialog));
            Engine.RegisterGlobalVariable("Engine", "NativeCommand", new Func<INpcPlayer, string, int>(Command));
            Engine.RegisterGlobalVariable("Engine", "FindPlayerByName", new Func<string, INpcPlayer>(FindPlayerByName));
            Engine.RegisterGlobalVariable("Engine", "FindPlayerByUID", new Func<uint, INpcPlayer>(FindPlayerByUID));
            Engine.RegisterGlobalVariable("Engine", "QueryDatabase", new Func<string, string, string, string, string>(QueryDatabase));
            Engine.RegisterGlobalVariable("Engine", "WriteDatabase", new Func<string, string, string, string, int>(WriteDatabase));
            Engine.RegisterGlobalVariable("Engine", "timeGetTime", new Func<uint>(timeGetTime));
            Engine.RegisterGlobalVariable("Engine", "GuildPoleID", new Func<ushort>(GuildPoleID));
            Engine.RegisterGlobalVariable("Engine", "FlipGate", new Func<uint, int>(FlipGate));
            Engine.RegisterGlobalVariable("Engine", "GenerateLotteryItem", new Func<int, INpcItem>(GenerateLotteryItem));
        }

        public static void Init()
        {
            Engine = new ScriptEngine("VB");
            Engine.Extension = GenerateExtension();
            Engine.BuildPath = ServerDatabase.Path + "\\Scripts\\";

            LinkScriptMethods();
            CreateDefinedFiles();
        }
11/23/2010 21:44 Basser#14
Can I add the scripting engine you made, still amazes me?
11/24/2010 07:58 ChingChong23#15
i don't like it, i feel it could be a lot easier. in my opinion that isn't user friendly, i actually find VB harder to look at than C# (obviously because im used to it).

An example of something i have set up:
Code:
SetText("Hello would you like to enter the PK Arena for 50 silvers?");
option = AddOptions("Yes, here you go.", "No thanks");
if(option == 1) {
 if(HasMoney(50)) {
  RemoveMoney(50);
  Teleport(1005, 50, 50);
 } else {
  SetText("I'm sorry you dont have 50 silvers.");
  AddOptions("Oh, I will go work my corner more.");
 }
}
maybe someone should create a thread on here about script engines and see what people can come up with, it can be judged by ease of use, speed and control.

From my old community i remember someone had the easiest setup i have ever seen, it went something like this


Code:
:start
text "Hello would you like to enter the PK Arena for 50 silvers?"
option1 "Yes, here you go."
option2 "No thanks."

:answer1
if hasmoney 50 goto tp else goto fail

:tp
money -50
teleport 1005 50 50

:fail
text "You dont have enough money"
option1 "Oh, I will go work my corner more"
i think above is pretty cool for end users.