[Release]NPC system 5165 simplified

12/10/2009 23:26 Kiyono#1
//
12/11/2009 00:24 Arcо#2
Quote:
Originally Posted by Kiyono View Post
I took a look at the NPCs and it annoyed me so this is to make the system simpler.

Add this in packethandling/npcdialog.cs
Code:
public static void Text(string value, Main.GameClient GC)
        {
            GC.AddSend(Packets.NPCSay(value));
        }
        public static void Link(string value, byte linkback, Main.GameClient GC)
        {
            GC.AddSend(Packets.NPCLink(value, linkback));
        }
        public static void Face(ushort face, Main.GameClient GC)
        {
            GC.AddSend(Packets.NPCSetFace(face));
        }
        public static void End(Main.GameClient GC)
        {
            GC.AddSend(Packets.NPCFinish());
        }
public static void Teleport(ushort map, ushort x, ushort y, Main.GameClient GC)
        {
            GC.MyChar.Teleport(map, x, y);
        }
Example:
Code:
 #region Leave TG
                            case 600075:
                                {
                                    if (Control == 0)
                                    {
                                        Text("Do you want to leave this place?", GC);
                                        Link("Yeah.", 1, GC);
                                        Link("No, I'll stay here.", 255, GC);
                                        Face(N.Avatar, GC);
                                        End(GC);
                                    }
                                    else if (Control == 1)
                                    {
                                        Game.Vector2 V = (Game.Vector2)Database.DefaultCoords[GC.MyChar.Loc.PreviousMap];
                                        Teleport(GC.MyChar.Loc.PreviousMap, V.X, V.Y, GC);
                                    }
                                    break;
                                }
                             #endregion
instead of

Code:
#region Leave TG
                            case 600075:
                                {
                                    if (Control == 0)
                                    {
                                        GC.AddSend(Packets.NPCSay("Do you want to leave this place?"));
                                        GC.AddSend(Packets.NPCLink("Yeah.", 1));
                                        GC.AddSend(Packets.NPCLink("No, I'll stay here.", 255));
                                        GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                        GC.AddSend(Packets.NPCFinish());
                                    }
                                    else if (Control == 1)
                                    {
                                        Game.Vector2 V = (Game.Vector2)Database.DefaultCoords[GC.MyChar.Loc.PreviousMap];
                                        GC.MyChar.Teleport(GC.MyChar.Loc.PreviousMap, V.X, V.Y);
                                    }
                                    break;
                                }
                            #endregion
I did not test this a lot though, the example provided is the only NPC I tested it on.

//edit Added Teleport.
Uhm I kinda released this already.
Only thing different about yours is the Teleport.
And you need to be specific on where to add the code.
Because it won't work just anywhere in the packethandler.
Please test stuff before you release it.
12/11/2009 00:39 airborne.#3
It's already simple, why is this needed...
12/11/2009 00:41 Arcо#4
Quote:
Originally Posted by airborne. View Post
It's already simple, why is this needed...

Because people get tired of typing
PHP Code:
GC.AddSend(Packets.NPCSay 
12/11/2009 01:28 Andrew.A#5
Quote:
Originally Posted by airborne. View Post
It's already simple, why is this needed...
Lol you say this is simple but so is adding an NPC to take you to a blank map
12/11/2009 02:37 Hitsugaya Toshiro#6
Tiku allready release something like this
But good job i guess =P
12/11/2009 13:42 Kiyono#7
Quote:
Originally Posted by Tiku View Post
Uhm I kinda released this already.
Only thing different about yours is the Teleport.
And you need to be specific on where to add the code.
Because it won't work just anywhere in the packethandler.
Please test stuff before you release it.
I didn't knew that you also released something like this.

//edit Also added removing/adding CPs/Silvers.
05/09/2010 17:18 MonstersAbroad#8
To make that even better you could do a NPC like
Code:
                            #region Leave TG
                            case 600075:
                                {
                                    switch (Control)
                                    {
                                        case 0:
                                            Text("Do you want to leave this place?", GC);
                                            Link("Yeah.", 1, GC);
                                            Link("No, I'll stay here.", 255, GC);
                                            break;

                                        case 1:
                                            Game.Vector2 V = (Game.Vector2)Database.DefaultCoords[GC.MyChar.Loc.PreviousMap];
                                            Teleport(GC.MyChar.Loc.PreviousMap, V.X, V.Y, GC);
                                            break;
                                    }
                                    Face(N.Avatar, GC);
                                    End(GC);
                                    break;
                                }
                                break;
That's how all my NPC's are coded and are a very good way to code NPC's also it makes npc's respond faster
05/09/2010 19:03 -impulse-#9
Quote:
Originally Posted by Kiyono View Post
I took a look at the NPCs and it annoyed me so this is to make the system simpler.

Add this in packethandling/npcdialog.cs
Code:
public static void Text(string value, Main.GameClient GC)
        {
            GC.AddSend(Packets.NPCSay(value));
        }
        public static void Link(string value, byte linkback, Main.GameClient GC)
        {
            GC.AddSend(Packets.NPCLink(value, linkback));
        }
        public static void Face(ushort face, Main.GameClient GC)
        {
            GC.AddSend(Packets.NPCSetFace(face));
        }
        public static void End(Main.GameClient GC)
        {
            GC.AddSend(Packets.NPCFinish());
        }
public static void Teleport(ushort map, ushort x, ushort y, Main.GameClient GC)
        {
            GC.MyChar.Teleport(map, x, y);
        }
public static void Silvers(uint value, Main.GameClient GC)
        {
            GC.MyChar.Silvers += value;
        }
        public static void CPs(uint value, Main.GameClient GC)
        {
            GC.MyChar.CPs += value;
        }
Example:
Code:
 #region Leave TG
                            case 600075:
                                {
                                    if (Control == 0)
                                    {
                                        Text("Do you want to leave this place?", GC);
                                        Link("Yeah.", 1, GC);
                                        Link("No, I'll stay here.", 255, GC);
                                        Face(N.Avatar, GC);
                                        End(GC);
                                    }
                                    else if (Control == 1)
                                    {
                                        Game.Vector2 V = (Game.Vector2)Database.DefaultCoords[GC.MyChar.Loc.PreviousMap];
                                        Teleport(GC.MyChar.Loc.PreviousMap, V.X, V.Y, GC);
                                    }
                                    break;
                                }
                             #endregion
instead of

Code:
#region Leave TG
                            case 600075:
                                {
                                    if (Control == 0)
                                    {
                                        GC.AddSend(Packets.NPCSay("Do you want to leave this place?"));
                                        GC.AddSend(Packets.NPCLink("Yeah.", 1));
                                        GC.AddSend(Packets.NPCLink("No, I'll stay here.", 255));
                                        GC.AddSend(Packets.NPCSetFace(N.Avatar));
                                        GC.AddSend(Packets.NPCFinish());
                                    }
                                    else if (Control == 1)
                                    {
                                        Game.Vector2 V = (Game.Vector2)Database.DefaultCoords[GC.MyChar.Loc.PreviousMap];
                                        GC.MyChar.Teleport(GC.MyChar.Loc.PreviousMap, V.X, V.Y);
                                    }
                                    break;
                                }
                            #endregion
To give 1000 silvers:
Code:
Silvers(+1000, GC);
To remove 1000 silvers:
Code:
Silvers(-1000, GC);
I did not test this a lot though, the example provided is the only NPC I tested it on.

//edit Added Teleport.
I'm sorry to tell you but using
Code:
public static void Silvers(uint value, Main.GameClient GC)
        {
            GC.MyChar.Silvers += value;
        }
        public static void CPs(uint value, Main.GameClient GC)
        {
            GC.MyChar.CPs += value;
        }
with
Silvers(-1000) will get your character like...max value of silvers?, it happens the same for CPs. You should use...
Code:
public static void Silvers(int value, Main.GameClient GC)
        {
            if(value <= 0 && GC.MyChar.Silvers < -value)
                return;
            GC.MyChar.Silvers = (uint)(GC.MyChar.Silvers + value);
        }
        public static void CPs(int value, Main.GameClient GC)
        {
            if(value <= 0 && GC.MyChar.CPs < -value)
                return;
            GC.MyChar.CPs = (uint)(GC.MyChar.CPs + value);
        }
05/10/2010 08:14 Arcо#10
Ah never woulda guess that.
+k alex.
Taught me a bit lol.
05/10/2010 08:17 .Summer#11
well, this is not really useful, if you can't use all methode types :)
like other statements instead of teleport, cps and silvers only :D
But also peoples get sone work then, to add them by them selves, but most peoples is just Copy + paste xD
05/10/2010 08:20 Arcо#12
Quote:
Originally Posted by .Summer View Post
well, this is not really useful, if you can't use all methode types :)
like other statements instead of teleport, cps and silvers only :D
But also peoples get sone work then, to add them by them selves, but most peoples is just Copy + paste xD
It can be done for all methods, not that hard.
05/10/2010 08:22 .Summer#13
Quote:
Originally Posted by .Arco View Post
It can be done for all methods, not that hard.
I know, i was talking for the copy + paste peoples :D
05/10/2010 08:26 Arcо#14
It's simple enough, I bet even they can do it xD
05/10/2010 08:32 .Summer#15
Quote:
Originally Posted by .Arco View Post
It's simple enough, I bet even they can do it xD
Yea true, is just some simple lines :D