NPC Locations

Newbie Spellweaver
Joined
May 4, 2007
Messages
41
Reaction score
0
Ok, I'm new to the whole C# programming language, but if someone can point me in the right direction, I would be grateful. How would I go about scripting NPC Locations, functions, etc... For example, I would like an NPC to stand in the middle of the city and offer people a nice piece of gear (such as +3 super armor... something of that sort.) Thanks in advance for any help. You can message me @ [email protected] with and advice. Thanks again.

***By the way, I'm using the LOFT source.
 
Last edited:
NPC locations are all coded in the database. To access the database, go into your browser and type localhost/phpmyadmin.
After that, open up coproj sql server, and go to NPCs.

The UID is the number that the database looks for in your source to see what the NPC says.
Ex: UID is 3000, the NPC would start with: if (CurrentNPC == 3000), then what the npc says, etc.

Type is the NPC Mech ID (what the NPC looks like)

Name is obvious lol

Direction is what way the NPC is facing, default, use 2 =P

X is the first coordinate number in the game (find this when playing in the server)
Y is the second coordinate number in the game
(for center of tc: X = 438, Y = 377)

Map is the map ID where the NPC will be located (EX: 1002 for Twin City)

Dont worry about SobType, you wont need this anytime soon, just use 0.

And there! you have your NPC placed!


Now you gotta code what it says. Heres an example of a code that would give an item:

Code:
                            if (CurrentNPC == 3000)
                            {
                                SendPacket(General.MyPackets.NPCSay("Want a free awesome Item???"));
                                SendPacket(General.MyPackets.NPCLink("Yes!!!!!!!", 1));
                                SendPacket(General.MyPackets.NPCLink("No.", 255));
                                SendPacket(General.MyPackets.NPCSetFace(30));
                                SendPacket(General.MyPackets.NPCFinish());
                            }

Code:
                            if (CurrentNPC == 3000)
                            {
                                if (Control == 1)
                                {
                                    MyChar.AddItem("130209-12-7-255-13-13", 0, (uint)General.Rand.Next(36457836));
                                    SendPacket(General.MyPackets.NPCSay("Theres your awesome freakin Item baby!"));
                                    SendPacket(General.MyPackets.NPCLink("Holy crap! Thank you lots dude!", 255));
                                    SendPacket(General.MyPackets.NPCSetFace(30));
                                    SendPacket(General.MyPackets.NPCFinish());

                                }
                            }

Btw, I just did this real quick =P
 
Thanks Super.Pvper for your quick response. One more question... say I only wanted the NPC to give the item once per account, how would I code this?
 
Thanks Super.Pvper for your quick response. One more question... say I only wanted the NPC to give the item once per account, how would I code this?

Well, there would be several ways to do this, ill show you the simplest.:jester:
(this definitally isnt the more efficient way)

Create a new table in Characters in teh database called something like ItemGet

Now, define it in your Character.cs file: public byte ItemGet = 0;

now, at the code wehre it gives the item, make MyChar.ItemGet = 1.

you must also modify the save code and more in database.cs

Code:
                            if (CurrentNPC == 3000)
                            {
                                if (MyChar.ItemGet = 1)
                                {
                                    SendPacket(General.MyPackets.NPCSay("You already got your kick ass item!"));
                                    SendPacket(General.MyPackets.NPCLink("Oh yeah, and it effin rulez!", 255));
                                    SendPacket(General.MyPackets.NPCSetFace(30));
                                    SendPacket(General.MyPackets.NPCFinish());
                                }
                                else
                                {
                                    SendPacket(General.MyPackets.NPCSay("Want a free awesome Item???"));
                                    SendPacket(General.MyPackets.NPCLink("Yes!!!!!!!", 1));
                                    SendPacket(General.MyPackets.NPCLink("No.", 255));
                                    SendPacket(General.MyPackets.NPCSetFace(30));
                                    SendPacket(General.MyPackets.NPCFinish());
                                }
                            }

Code:
                            if (CurrentNPC == 3000)
                            {
                                if (Control == 1)
                                {
                                    MyChar.AddItem("130209-12-7-255-13-13", 0, (uint)General.Rand.Next(36457836));
                                    SendPacket(General.MyPackets.NPCSay("Theres your awesome freakin Item baby!"));
                                    SendPacket(General.MyPackets.NPCLink("Holy crap! Thank you lots dude!", 255));
                                    SendPacket(General.MyPackets.NPCSetFace(30));
                                    SendPacket(General.MyPackets.NPCFinish());

                                }
                            }

In database.cs

Code:
Charr.ItemGet =Convert.ToByte((byte)DR["ItemGet"]);

Add this to MySqlCommand Command = new MySqlCommand("UPDATE `Characters`...
Code:
`ItemGet` = '" + Charr.ItemGet + "'


Edit: add me on MSN if you wanna discuss this. [email protected]
 
Awesome bro, thank you. I've added you to msn.

What do I do about this error?

Error 1 Cannot implicitly convert type 'byte' to 'bool'
 
Back