Jump to content
metin2dev
Ekstasia2
Nevisor

c++ [C++] Channel Changer gf-like

Recommended Posts

Hey,

Move Channel System with countdown (same as logout, change character and quit), similar to gf.

command: /move_channel number

Files to edit char.cpp, char.h, cmd.cpp, cmd.h, cmd_general.cpp

char.cpp

Spoiler

find


void CHARACTER::StartWarpNPCEvent()

add above


// MOVE_CHANNEL
void CHARACTER::MoveChannel(int iNewChannel)
{
	long lAddr, lMapIndex;
	WORD wPort;

	long x = GetX();
	long y = GetY();

	if (!CMapLocation::Instance().Get(x, y, lMapIndex, lAddr, wPort))
		return;

	std::map<WORD, BYTE> ChannelsPorts;
	for (BYTE i = 0; i < 6; i++) //replace with maximum channels
	{
		//core1
		ChannelsPorts[13 * 1000 + i] = i + 1; // 1300i - channel port 
		//core2
		//ChannelsPorts[13 * 1000 + 50 + i] = i + 1; // 1305i - channel port
		//etc.
	}

	int iChannel = ChannelsPorts.find(wPort) != ChannelsPorts.end() ? ChannelsPorts[wPort] : 0;

	Stop();
	Save();

	if (GetSectree())
	{
		GetSectree()->RemoveEntity(this);
		ViewCleanup();
		EncodeRemovePacket(this);
	}

	TPacketGCWarp p;
	p.bHeader = HEADER_GC_WARP;
	p.lX = x;
	p.lY = y;
	p.lAddr = lAddr;
	p.wPort = (wPort - (iChannel - 1) + (iNewChannel - 1));

	GetDesc()->Packet(&p, sizeof(TPacketGCWarp));
}
// END_OF_MOVE_CHANNEL

 

char.h

Spoiler

find


		void				StartWarpNPCEvent();

add bellow


		// MOVE_CHANNEL
		void                MoveChannel(int new_ch);
		// END_OF_MOVE_CHANNEL

 

cmd.cpp

Spoiler

find


	{ "mall_close",	do_mall_close,		0,			POS_DEAD,	GM_PLAYER	},

add bellow


	// MOVE_CHANNEL
	{ "move_channel", do_cmd, SCMD_MOVE_CHANNEL, POS_DEAD, GM_PLAYER },
	// END_OF_MOVE_CHANNEL

 

cmd.h

Spoiler

find


struct command_info

add above


// MOVE_CHANNEL
extern int channel_index;
// END_OF_MOVE_CHANNEL

 

cmd_general.cpp

Spoiler

1) find


extern int g_server_id;

1) add above


// MOVE_CHANNEL
#include "map_location.h"
// END_OF_MOVE_CHANNEL

2) find


			switch (info->subcmd)
			{
				case SCMD_LOGOUT:
				case SCMD_QUIT:
				case SCMD_PHASE_SELECT:

2) add bellow


				// MOVE_CHANNEL
				case SCMD_MOVE_CHANNEL:
				// END_OF_MOVE_CHANNEL

3) find


			case SCMD_PHASE_SELECT:
				{
					ch->Disconnect("timed_event - SCMD_PHASE_SELECT");

					if (d)
					{
						d->SetPhase(PHASE_SELECT);
					}
				}
				break;

3) add bellow


			// MOVE_CHANNEL
			case SCMD_MOVE_CHANNEL:
				ch->MoveChannel(channel_index);
				break;
			// END_OF_MOVE_CHANNEL

4) find


		case SCMD_PHASE_SELECT:
			ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Äł¸ŻĹ͸¦ ŔüČŻ ÇŐ´Ď´Ů. Ŕá˝Ă¸¸ ±â´Ů¸®ĽĽżä."));
			break;

4) add bellow


		// MOVE_CHANNEL
		case SCMD_MOVE_CHANNEL:
			//ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("SCMD_MOVE_CHANNEL"));
			char arg1[256];
			one_argument(argument, arg1, sizeof(arg1));
			if (!*arg1)
				return;

			int new_ch;
			str_to_number(new_ch, arg1);
			if (new_ch < 1 || new_ch > 6)   // replace with your channel count
				return;
			if (!ch->IsPC())
				return;
			channel_index = new_ch;
			break;
		// END_OF_MOVE_CHANNEL

5) find


		case SCMD_LOGOUT:
		case SCMD_QUIT:
		case SCMD_PHASE_SELECT:
		{
			TimedEventInfo* info = AllocEventInfo<TimedEventInfo>();

			{
				if (ch->IsPosition(POS_FIGHTING))
					info->left_second = 10;
				else
					info->left_second = 3;
			}

			info->ch		= ch;
			info->subcmd		= subcmd;
			strlcpy(info->szReason, argument, sizeof(info->szReason));

			ch->m_pkTimedEvent	= event_create(timed_event, info, 1);
		}
		break;

5) add bellow


		// MOVE_CHANNEL
		case SCMD_MOVE_CHANNEL:
		{
			int lMapArray[] = { 66, 113, 207 }; // disallowed map index

			long lAddr, lMapIndex;
			WORD wPort;

			long x = ch->GetX();
			long y = ch->GetY();

			if (!CMapLocation::Instance().Get(x, y, lMapIndex, lAddr, wPort))
			{
				sys_err("Can not find map location index[%ld] x[%ld] y[%ld] name[%s]", lMapIndex, x, y, ch->GetName());
				return;
			}

			if (lMapIndex >= 10000)
			{
				sys_err("Map index higher or equal to 10000");
				return;
			}

			for (int i = 0; i < _countof(lMapArray); i++)
			{
				if (lMapIndex == lMapArray[i])
				{
					ch->ChatPacket(CHAT_TYPE_INFO, "You can't change channel while you're inside this location");
					return;
				}
			}
			

			std::map<WORD, BYTE> ChannelsPorts;
			for (BYTE i = 0; i < 6; i++) //replace with maximum channels
			{
				//core1
				ChannelsPorts[13 * 1000 + i] = i + 1; // channel port
				//core2
				//ChannelsPorts[13 * 1000 + 50 + i] = i + 1; // channel port
				//etc.
			}

			int iChannel = ChannelsPorts.find(wPort) != ChannelsPorts.end() ? ChannelsPorts[wPort] : 0;

			if (iChannel == 0)
			{
				ch->ChatPacket(CHAT_TYPE_INFO, "This port is not available! (%d)", wPort);
				return;
			}

			if (wPort == (wPort - (iChannel - 1) + (channel_index - 1)))
			{
				ch->ChatPacket(CHAT_TYPE_INFO, "You're on this channel, select another one!");
				return;
			}

			TimedEventInfo* info = AllocEventInfo<TimedEventInfo>();

			{
				if (ch->IsPosition(POS_FIGHTING))
					info->left_second = 10;
				else
					info->left_second = 3;
			}

			ch->ChatPacket(CHAT_TYPE_INFO, "Please wait a moment. Changing channel...");

			info->ch = ch;
			info->subcmd = subcmd;
			strlcpy(info->szReason, argument, sizeof(info->szReason));

			ch->m_pkTimedEvent = event_create(timed_event, info, 1);
		}
		break;
		// END_OF_MOVE_CHANNEL

 

 

CALCULATE YOUR PORTS HERE

https://repl.it/@Nevisor/ChannelPortCalculator

  • Like 2

Share this post


Link to post
Share on other sites

Thanks, if anyone is willing to share the zip with the official buttons for the switcher i can make the official interface (a video of the official channel changer would be great since i have no idea how it looks)

Share this post


Link to post
Share on other sites
On 30. 9. 2017 at 6:11 PM, Nevisor said:

btw. I've already made python part too (update 1.4 contains all files)

 

I tried your python part but when I change channel, channel info (under minimap) is still same..
How Can I fix it? Thanks.

Share this post


Link to post
Share on other sites
4 godziny temu, .Rise napisał:

I tried your python part but when I change channel, channel info (under minimap) is still same..
How Can I fix it? Thanks.

net.SetServerInfo("Server, Channel: %d" % channel)

Share this post


Link to post
Share on other sites
5 godzin temu, .Rise napisał:

I tried your python part but when I change channel, channel info (under minimap) is still same..
How Can I fix it? Thanks.

There is part in my game.py that is doing that as I remember

  • Thanks 1

Share this post


Link to post
Share on other sites
9 hours ago, Nevisor said:

There is part in my game.py that is doing that as I remember

Ok.. it is solved now but there is another bug:
when I am shopping and try to change channel (click on "OK"), after teleport it will refresh on chosen channel instead of staying, because I cant change channel while shopping..

Share this post


Link to post
Share on other sites

Hey there fellow dev's anyone know why i get these two and how to fix these ?

cmd_general.cpp:502: undefined reference to `channel_index' :

Which is :

			case SCMD_MOVE_CHANNEL:
				ch->MoveChannel(channel_index);
				break;


cmd_general.cpp:647: undefined reference to `channel_index'

Which is :

			if (wPort == (wPort - (iChannel - 1) + (channel_index - 1)))
			{
				ch->ChatPacket(CHAT_TYPE_INFO, "You're on this channel, select another one!");
				return;
			}

 

I would be really happy if someone could kindly help me with this matter.

Regards, 

Danonek

 

Share this post


Link to post
Share on other sites

Anyone con help me with set ch port in the char.cpp????

ch1 core 1 31000

ch1 core 2 33000

ch2 core 1 31001

ch2 core 2 33001

Share this post


Link to post
Share on other sites
Dnia 27.10.2018 o 07:02, kertus napisał:

Anyone con help me with set ch port in the char.cpp????

ch1 core 1 31000

ch1 core 2 33000

ch2 core 1 31001

ch2 core 2 33001

//cor1
ChannelsPorts[31 * 1000 + i] = i + 1;
//cor2
ChannelsPorts[33 * 1000 + i] = i + 1;

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×