[Release] cq_actions for COEMU v2

05/29/2009 15:50 nTL3fTy#16
Quote:
Originally Posted by $HaDoW View Post
works but it has bugs and still lots of ranslate and codeing is waiting !
Explain the bugs please.
05/29/2009 16:14 $HaDoW#17
some npcs dont do what they have to do ! gives free stuff and so on !
05/29/2009 22:40 ~*Dutchess*~#18
default:
{
if (LinkBack == 0)
{
CSocket.Client.NpcTasks.Clear();<-- error
Database.Database.GetNPCTask(ID, CSocket);
break;
}
else
{
int task = 0;
foreach (DictionaryEntry DE in CSocket.Client.NpcTasks)<-- Error
{
if (Convert.ToInt32(DE.Key) == LinkBack)
{ task = Convert.ToInt32(DE.Value); }
}
Database.Database.GetTaskAction(task, CSocket);
break;
}
05/30/2009 01:40 felipeboladao#19
Quote:
Originally Posted by ~*Dutchess*~ View Post
default:
{
if (LinkBack == 0)
{
CSocket.Client.NpcTasks.Clear();<-- error
Database.Database.GetNPCTask(ID, CSocket);
break;
}
else
{
int task = 0;
foreach (DictionaryEntry DE in CSocket.Client.NpcTasks)<-- Error
{
if (Convert.ToInt32(DE.Key) == LinkBack)
{ task = Convert.ToInt32(DE.Value); }
}
Database.Database.GetTaskAction(task, CSocket);
break;
}
Go to Database and search for

Code:
static void GetNPCTask(int MyID, ClientSocket CSocket)
And replace

Code:
public static void GetNPCTask(int MyID, ClientSocket CSocket)
05/30/2009 01:46 nTL3fTy#20
Quote:
Originally Posted by felipeboladao View Post
Go to Database and search for

Code:
static void GetNPCTask(int MyID, ClientSocket CSocket)
And replace

Code:
public static void GetNPCTask(int MyID, ClientSocket CSocket)
His problem is that he didn't define the variable..
07/11/2009 23:49 Kiyono#21
I was wondering if this was still being developed? oh and #bump
07/12/2009 00:33 Arcotemple:)#22
Quote:
Originally Posted by master15 View Post
im coding a system to read the cq_nps, check the cq_task and load cq_actions

there is just some types working yet:

Npc Text,
Npc Link,
Npc Face,
Npc End,
Npc Char stats Check (not all coded),
Npc Teleport,
Npc Save old MapID, X, and Y when you are teleported


Now let's start

into GameServerProject find it: public static void LoadNpcs() in Database.cs

change to:

Code:
	public static void LoadNpcs()
		{
			MySqlCommand Cmd = new MySqlCommand("SELECT * FROM `cq_npc`", DatabaseConnection.NewConnection());
			MySqlDataReader DR = Cmd.ExecuteReader(CommandBehavior.CloseConnection);
			while(DR.Read())
			{
				Struct.NPC NPC = new Struct.NPC();
				NPC.Direction = Convert.ToInt32(DR["type"]);
				NPC.Flag = Convert.ToInt32(DR["sort"]);
				NPC.ID = Convert.ToInt32(DR["id"]);
				NPC.Map = Convert.ToInt32(DR["mapid"]);
				NPC.SubType = Convert.ToInt32(DR["lookface"]);
				NPC.Type = Convert.ToInt32(DR["id"]);
				NPC.X = Convert.ToInt32(DR["cellx"]);
				NPC.Y = Convert.ToInt32(DR["celly"]);
				if(!Nano.Npcs.ContainsKey(NPC.ID))
					Nano.Npcs.Add(NPC.ID, NPC);
			}
			Console.WriteLine("[GameServer] Loaded " + Nano.Npcs.Count + " npcs into the world.");
			DR.Close();
			Cmd.Dispose();
		}
now bellow of it add this voids:

Code:
 public static void GetNPCTask(int MyID, ClientSocket CSocket)
        {
            MySqlCommand Cmd = new MySqlCommand("SELECT * FROM `cq_npc` WHERE `id` = " + MyID + "", DatabaseConnection.NewConnection());
            MySqlDataReader DR = Cmd.ExecuteReader(CommandBehavior.CloseConnection);
            while (DR.Read())
            {
                int task0 = Convert.ToInt32(DR["task0"]);
                int task1 = Convert.ToInt32(DR["task1"]);
                int actions = 0;
                if (task0 != 0) { actions = task0; }
                else if (task1 != 0) { actions = task1; }

                if (actions != 0)
                {
                    GetTaskAction(task0, CSocket);
                }
            }
            DR.Close();
            Cmd.Dispose();
        }
        public static void LoadActions(int ActionID, ClientSocket CSocket)
        {
            MySqlCommand CMD = new MySqlCommand("SELECT * FROM `actions` WHERE `id` = " + ActionID + "", DatabaseConnection.NewConnection());
            MySqlDataReader DR = CMD.ExecuteReader(CommandBehavior.CloseConnection);
            while (DR.Read())
            {
                bool callfail = false;

                int id_next = Convert.ToInt32(DR["id_next"]);
                int id_fail = Convert.ToInt32(DR["id_nextfail"]);
                int type = Convert.ToInt32(DR["type"]);
                int data = Convert.ToInt32(DR["data"]);
                string param = Convert.ToString(DR["param"]);

                if (type == 101) //npc text
                {
                    param.Replace("%user_name", CSocket.Client.Name);

                    Handlers.Handler.Text(param, CSocket);
                }
                else if (type == 102) //npc link
                {
                    string[] spit = param.Split(' ');
                    int a = CSocket.Client.NpcTasks.Count +1;
                    int link = 0;

                    try { link = Convert.ToInt32(spit[1]); }
                    catch { }

                    CSocket.Client.NpcTasks.Add(a, link);
                    Handlers.Handler.Link(spit[0], a, CSocket);
                }
                else if (type == 103)//npc input
                {
                    string[] spit = param.Split(' ');
                    int a = CSocket.Client.NpcTasks.Count + 1;
                    int link = 0; int unk = 0;

                    try { link = Convert.ToInt32(spit[1]); unk = Convert.ToInt32(spit[0]); }
                    catch { }

                    CSocket.Client.NpcTasks.Add(a, link);
                    Handlers.Handler.Input(spit[2], link, CSocket);
                }
                else if (type == 104)//npc face
                {
                    string[] spit = param.Split(' ');
                    int face = 0;

                    try { face = Convert.ToInt32(spit[2]); }
                    catch { }

                    Handlers.Handler.Face(face, CSocket);
                }
                else if (type == 120)//npc end
                { Handlers.Handler.End(CSocket); }
                else if (type == 1001)//check user
                {
                    string[] spit = param.Split(' ');
                    string tocheck = spit[0];  string operatorr = spit[1]; string value = spit[2];

                    callfail = NpcActions.TQCheckUserStats(tocheck, operatorr, value, CSocket);
                }
                else if (type == 1003)//transport to map
                {
                     string[] spit = param.Split(' ');
                     Handlers.Handler.Teleport(int.Parse(spit[0]), int.Parse(spit[1]), int.Parse(spit[2]), 0, CSocket);
                }
                else if (type == 1004) //save map
                {
                    string[] spit = param.Split(' ');
                    CSocket.Client.RecordMap = int.Parse(spit[0]);
                    CSocket.Client.RecordX = int.Parse(spit[1]);
                    CSocket.Client.RecordY = int.Parse(spit[2]);
                    Database.SaveCharacter(CSocket.Client);
                }
                else if (type == 1006) //transport to recored map
                {
                    Handlers.Handler.Teleport(CSocket.Client.RecordMap, CSocket.Client.RecordX, CSocket.Client.RecordY, 0, CSocket);
                }
                if (id_next != 0 && callfail == false) { LoadActions(id_next, CSocket); }

                if (id_fail != 0 && callfail == true) { LoadActions(id_fail, CSocket); }

            }
            CMD.Dispose();
            DR.Close();
        }
        public static void GetTaskAction(int taskID, ClientSocket CSocket)
        {
            MySqlCommand CMD = new MySqlCommand("SELECT * FROM `task` WHERE `id` = " + taskID + "", DatabaseConnection.NewConnection());
            MySqlDataReader DR = CMD.ExecuteReader(CommandBehavior.CloseConnection);
            while (DR.Read())
            {
                int id_next = Convert.ToInt32(DR["id_next"]);
                LoadActions(id_next, CSocket);
            }
            CMD.Dispose();
            DR.Close();
        }
now go to handlers folder and open NpcTalk.cs and replace all the lines for this

Code:
/*
 * Created by SharpDevelop.
 * User: sams
 * Date: 3/18/2009
 * Time: 8:02 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections;
using System.Collections.Generic;
using CoEmu_v2_GameServer.Connections;
using CoEmu_v2_GameServer.Entities;
using CoEmu_v2_GameServer.Structs;
using CoEmu_v2_GameServer.Packets;
using CoEmu_v2_GameServer.Calculations;
using Lua511;
using LuaInterface;

namespace CoEmu_v2_GameServer.Handlers
{
	/// <summary>
	/// Description of NpcTalk.
	/// </summary>
	public partial class Handler
	{
		public static void NpcTalk(ClientSocket CSocket, int ID, int LinkBack)
		{
			if(ID > 0)
				CSocket.Client.LastNPC = ID;
			switch(ID)
			{
				case 8://TC - WHS
					{
						CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog));
						break;
					}
				case 10012://PC - WHS
					{
						CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog));
						break;
					}
				case 10011://DC - WHS
					{
						CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog));
						break;
					}
				case 10028://AM - WHS
					{
						CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog));
						break;
					}
				case 10027://BI - WHS
					{
						CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog));
						break;
					}
				case 44://MA - WHS
					{
						CSocket.Send(ConquerPacket.General(CSocket.Client.ID, 4, 0, 0, 0, 0, Struct.DataType.Dialog));
						break;
					}
					default:
					{
                        if (LinkBack == 0)
                        {
                            CSocket.Client.NpcTasks.Clear();
                            Database.Database.GetNPCTask(ID, CSocket);
                            break;
                        }
                        else
                        {
                            int task = 0;
                            foreach (DictionaryEntry DE in CSocket.Client.NpcTasks)
                            {
                                if (Convert.ToInt32(DE.Key) == LinkBack)
                                { task = Convert.ToInt32(DE.Value); }
                            }
                            Database.Database.GetTaskAction(task, CSocket);
                            break;
                        }
					}
			}
		}
		public static void Text(string value, ClientSocket CSocket)
		{
			CSocket.Send(ConquerPacket.NPCTalk(255, 1, value));
		}
		public static void Money(int value, ClientSocket CSocket)
		{
			CSocket.Client.Money += value;
			CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.Money, Struct.StatusTypes.InvMoney));
		}
		public static void CPs(int value, ClientSocket CSocket)
		{
			CSocket.Client.CPs += value;
			CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.CPs, Struct.StatusTypes.InvCPoints));
		}
		public static void Link(string value, int LinkBack, ClientSocket CSocket)
		{
			CSocket.Send(ConquerPacket.NPCTalk(LinkBack, 2, value));
		}
		public static void Input(string text, int LinkBack, ClientSocket CSocket)
		{
			CSocket.Send(ConquerPacket.NPCTalk(LinkBack, 3, text));
		}
        public static void Face(int Face, ClientSocket CSocket)
        {
            CSocket.Send(ConquerPacket.NPCTalk(2544, Face, 255, 4));
        }
		public static void End(ClientSocket CSocket)
		{
			CSocket.Send(ConquerPacket.NPCTalk(0, 0, 255, 100));
		}
	}
}
now go find it: public bool Dead = false; in Character.cs

and under of this code add:

Code:
public Hashtable NpcTasks = new Hashtable();//temp npctask loads

        public int RecordMap = 1002;
        public int RecordX = 438;
        public int RecordY = 377;
now, go to Database.cs again and find it: Client.Class = (Struct.ClassType)Convert.ToInt32(DR["Class"]);

bellow of it add

Client.RecordMap = Convert.ToInt32(DR["RecordMap"]);
Client.RecordX = Convert.ToInt32(DR["RecordX"]);
Client.RecordY = Convert.ToInt32(DR["RecordY"]);

and now find it: public static void SaveCharacter(Character Client)

and change for

Code:
public static void SaveCharacter(Character Client)
		{
            MySqlCommand Cmd = new MySqlCommand("UPDATE `characters` SET `Level` = " + Client.Level + ", `WHMoney` = " + Client.WHMoney + ", `PkPoints` = " + Client.PkPoints + ", `xCord` = " + Client.X + ", `yCord` = " + Client.Y + ", `Map` = " + (int)Client.Map + ", `HairStyle` = " + Client.Hair + ", `Class` = " + (int)Client.Class + ", `Exp` = " + Client.Exp + ", `Money` = " + Client.Money + ", `Str` = " + Client.Strength + ",`Vit` = " + Client.Vitality + ", `Spi` = " + Client.Spirit + ", `Dex` = " + Client.Dexterity + ", `StatPoints` = " + Client.StatPoints + ", `FirstLog` = " + 1 + ", `Reborn` = " + Client.Reborn + ", `HP` = " + Client.CurrentHP + ", `MP` = " + Client.CurrentMP + ", `RecordMap` = " + Client.RecordMap + ", `RecordX` = " + Client.RecordX + ", `RecordY` = " + Client.RecordY +" WHERE `CharID` = " + Client.ID, DatabaseConnection.NewConnection());
			Cmd.ExecuteNonQuery();
			Cmd.Connection.Close();
			Cmd.Connection.Dispose();
			Cmd.Dispose();
		}
now add in the project the NpcActions.cs (NpcActions.cs.rar)

and execute the batch of my sql (it will add table: actions, task, cq_npc, and update the character table (Junior_SQL.rar)

Credits goto:

Me (all code is mine work)
felipeboladao (for a little help) thx dude
magnon for the cq_actions very thx

More Updates coming soon when i get free time to code
and for who have a must english database and want help me/us to make it much perfect pm me
good job, imnot gonna use since im strictly a lotf user lol
07/12/2009 00:40 m7med#23
i add the npcactions.cs in CoEmu v2\CoEmu v2 GameServer\Handlers are this right or not
and i have this only error
The name 'NpcActions' does not exist in the current context
please help
07/14/2009 18:17 hunterman01#24
Quote:
Originally Posted by Arcotemple:) View Post
good job, imnot gonna use since im strictly a lotf user lol
Sometimes you have to move on to bigger and better things 0.0
07/14/2009 18:44 sawickas#25
For me it dont work i add npctalk.cs but have a lot of erors if any body make it work uplaud it here thanks
10/13/2009 12:16 gulpi_de_gulat#26
no error but nothing happens still desame
10/13/2009 12:33 sawickas#27
Quote:
Originally Posted by gulpi_de_gulat View Post
no error but nothing happens still desame
yuo need build,and if no erors can yuo post it plyz?
10/13/2009 12:46 PropItem#28
Quote:
Originally Posted by IcedEarth View Post
lawl ? I just tried and it works just fine :)
UMM HAY MILEY IM A "NOT FAN" btw arnt you a guy...



@Topic - nice coding in MYSQL
10/13/2009 13:53 ImmortalYashi#29
You guys should write your own npc talk system..
11/12/2009 19:50 darkichou#30
i got some problems :S
it says that the 'CoEmu_v2_GameServer.Packets.ConquerPacket' don't know what is 'NPCTalk'