Jump to content

Send whisper message (DM) from quest


Recommended Posts

Hello.

I saw a similar question earlier on this forum, and since it's not a big task, I quickly made this snippet. It doesn't require much explanation, you can send a whisper message from a guest using a function.

 

Let's see:

I. Open the "game/src/questlua_pc.cpp" and you have to look for the following function::

int pc_set_skill_level(lua_State* L)
{
	...
}

 

II. and after that whole function lines add the following function lines:

int pc_send_whisper(lua_State* L)
{
	LPCHARACTER lpCH = CQuestManager::instance().GetCurrentCharacterPtr();
	
	int iArgIndex = 1;
	const char * c_szSenderName = "System";
	if (lua_gettop(L) > 1)
	{
		if(!lua_isstring(L, iArgIndex))
		{
			sys_err("QUEST : wrong argument");
			lua_pushboolean(L, false);
			return 1;
		}
		
		c_szSenderName = lua_tostring(L, iArgIndex);
		if (strlen(c_szSenderName) == 0)
		{
			sys_err("QUEST : empty argument");
			lua_pushboolean(L, false);
			return 1;
		}
		
		iArgIndex++;
	}
	
	if (!lua_isstring(L, iArgIndex))
	{
		sys_err("QUEST : wrong argument");
		lua_pushboolean(L, false);
		return 1;
	}
	
	const char * c_szMessage = lua_tostring(L, iArgIndex);
	const size_t c_size = (c_szMessage) ? strlen(c_szMessage)  : 0;
	if (c_size == 0)
	{
		sys_err("QUEST : empty argument");
		lua_pushboolean(L, false);
		return 1;
	}
	
	LPDESC lpDesc;
	if (!(lpDesc = lpCH->GetDesc()))
	{
		lua_pushboolean(L, false);
		return 1;
	}
	
	TPacketGCWhisper lPack;
	lPack.bHeader = HEADER_GC_WHISPER;
	lPack.wSize = sizeof(TPacketGCWhisper) + c_size;
	lPack.bType = WHISPER_TYPE_NORMAL;
	strlcpy(lPack.szNameFrom, c_szSenderName, sizeof(lPack.szNameFrom));
	
	TEMP_BUFFER lTmpBuf;
	lTmpBuf.write(&lPack, sizeof(lPack));
	lTmpBuf.write(c_szMessage, c_size);
	
	lpDesc->Packet(lTmpBuf.read_peek(), lTmpBuf.size());
	
	lua_pushboolean(L, true);
	return 1;
}

 

III. and now, look for the following line in the "RegisterPCFunctionTable" function:

{ "set_skill_level",        pc_set_skill_level      },

 

 IV. and before that line add the following line:

{ "send_whisper",		pc_send_whisper	},

 

We are done now ! 🙂

Important: You have to check your own whisper packet structure, because mine and yours can be different maybe.

Don't forget to add this new quest function name to the quest function list file! (If you have one, that is.) - pc.send_whisper

 

   Usage example: (The default whisper target is always the current selected player by the quest system.)

-- To send message by default sender name as "System":
pc.send_whisper("Hi there! :)")

-- To send message by a given sender name:
pc.send_whisper("Biologist", "Biolog cooldown is done, you can submit next item.")

-- To check the success of send:
if pc.send_whisper("Hi there! :)") then
  -- The whisper message has been sent successfully.
else
  -- Failed to send the whisper message.
end
Edited by UdvAtt108
wrong word
  • Metin2 Dev 9
  • Good 4
  • Love 1
  • Love 4

All wolves are gray in the dark.

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.