Custom PrintToPlayer/PrintToServer Stuff

User avatar
tagban
Posts: 352
Joined: Fri Dec 28, 2012 11:31 am
Location: Pennsylvania, USA

Custom PrintToPlayer/PrintToServer Stuff

Post by tagban » Tue Dec 30, 2014 6:06 pm

UPDATED: 1/2/2015 (second time)
-- Adjusted PrintToServer to use MessageServer so servers with multiple game servers hosting zones will function properly.
----
Fairly customized, but I decided to re-modify/research and with a lot of help From Kj, atom0s, and Demolish, I think we have it pretty awesome now.

First, at the top of lua_baseentity.cpp in the declarations:

Code: Select all

#include"../message.h"
Next:
lua_baseentity.cpp
Find: inline int32 CLuaBaseEntity::PrintToPlayer
Remove existing PrintToPlayer and replace with this:

Code: Select all

inline int32 CLuaBaseEntity::PrintToPlayer(lua_State* L)
{
	DSP_DEBUG_BREAK_IF(m_PBaseEntity == NULL);
	DSP_DEBUG_BREAK_IF(m_PBaseEntity->objtype != TYPE_PC);
	DSP_DEBUG_BREAK_IF(lua_isnil(L, 1) || !lua_isstring(L, 1));
	CHAT_MESSAGE_TYPE messageType = (!lua_isnil(L, 2) && lua_isnumber(L, 2) ? (CHAT_MESSAGE_TYPE)lua_tointeger(L, 2) : MESSAGE_SYSTEM_1);
	((CCharEntity*)m_PBaseEntity)->pushPacket(new CChatMessagePacket((CCharEntity*)m_PBaseEntity, messageType, (char*)lua_tostring(L, 1)));
	return 0;
}

inline int32 CLuaBaseEntity::PrintToServer(lua_State* L)
{
	DSP_DEBUG_BREAK_IF(m_PBaseEntity == NULL);
	DSP_DEBUG_BREAK_IF(m_PBaseEntity->objtype != TYPE_PC);
	DSP_DEBUG_BREAK_IF(lua_isnil(L, 1) || !lua_isstring(L, 1));
	CHAT_MESSAGE_TYPE messageType = (!lua_isnil(L, 2) && lua_isnumber(L, 2) ? (CHAT_MESSAGE_TYPE)lua_tointeger(L, 2) : MESSAGE_SYSTEM_1);
	message::send(MSG_CHAT_SERVMES, 0, 0, new CChatMessagePacket((CCharEntity*)m_PBaseEntity, messageType, (char*)lua_tostring(L, 1)));
	return 0;
}
In the same file, find this line:
LUNAR_DECLARE_METHOD(CLuaBaseEntity,PrintToPlayer),
Add below it:

Code: Select all

	LUNAR_DECLARE_METHOD(CLuaBaseEntity,PrintToServer),
Great! Lastly, lua_baseentity.h
Find line: int32 PrintToPlayer(lua_State* L);
Add below it:

Code: Select all

	int32 PrintToServer(lua_State* L);    // Print to SERVER (Prints to every zone on the server) -- Defaults to System Message, but can be altered with HEX or Integer of type of text
------------------
So what does that let you do? A lot! You can now modify any place in Lua files that has "PrintToPlayer" to add some color/special stuff, etc.
Examples:
player.lua -> Under OnGameIn If Not Zoning:

Code: Select all

player:PrintToServer(string.format("The character %s has logged in...", player:getName()), 0x1C);
-- Sends a message to everyone on the server letting you know someone logged in. This comes thru in colored chat text, and could easily be modified to be more simple such as:

Code: Select all

player:PrintToServer(" -- Logged In", 8);
This will display the player: Tagban -- Logged In but in the emote color text.
--------
We have special Linkshells on our server, so another message a new player will recieve is this:

Code: Select all

player:PrintToPlayer("You are now in the BNETcc Linkshell", 0x10);
This will come thru in Linkshell colored chat. Looks pretty nice. :)

I'm planning on adding some more simplified names in status.lua file shortly, to make this simpler instead of having to use hex/numbers, but for now this is functional, and stable. One word of warning, the gmtell chat.. It seems to open up a message box. Not exactly sure what can all be done with it yet.. But it seems cool to play with.

My @test command to check out the colors:

Code: Select all

---------------------------------------------------------------------------------------------------
-- func: @testcolors
-- auth: Tagban
-- desc: Test Command to check colors are working for debugging. 
---------------------------------------------------------------------------------------------------

cmdprops =
{
    permission = 1,
    parameters = "s"
};


function onTrigger(player)
	player:PrintToPlayer("Say MESSAGE_SAY 0", 0);
	player:PrintToPlayer("Shout MESSAGE_SHOUT 1", 1);
	player:PrintToPlayer("Emote MESSAGE_EMOTE 8", 8);
	player:PrintToPlayer("Yell MESSAGE_YELL 0x1A", 0x1A);
	player:PrintToPlayer("Tell MESSAGE_TELL 3", 3);
	player:PrintToPlayer("Party/Alliance MESSAGE_PARTY 4", 4);
	player:PrintToPlayer("Linkshell 1 MESSAGE_LINKSHELL 5", 5);
	player:PrintToPlayer("Linkshell 2 msgTypeLS2 0x1B", 0x1B);
	player:PrintToPlayer("Linkshell 3 msgTypeLS3 0x1E", 0x1E);
	player:PrintToPlayer("Unity Msg msgTypeUnity 0x21", 0x21);
	player:PrintToPlayer("SystemMessage MESSAGE_SYSTEM_1 6", 6);
	player:PrintToPlayer("Msg Only (Yellow) msgTypeYellow 0x15", 0x15);
	player:PrintToPlayer("Msg Only (White like Say) msgTypeWhite 0xD", 0xD);
	player:PrintToPlayer("Msg Only (Pinkish like Shout) msgTypePink 0xE", 0xE);
	player:PrintToPlayer("Msg Only (Lime like Linkshell) msgTypeLime 0x10", 0x10);
	player:PrintToPlayer("Msg Only (Green) msgTypeGreen 0x1C", 0x1C);
	player:PrintToPlayer("Msg Only Generic Yellow 0x1F", 0x1F);
	player:PrintToPlayer("Msg Only (Blue) msgTypeBlue 0xF", 0xF);
	player:PrintToPlayer("---- Test Complete ----", 8);
end;
Image
-------------------
Hope you enjoy this! There are a few other chat things that atom0s had posted which is what started me on messing with this stuff. Gold/Yellow appear to be the same, so I removed GOLD from this post.
--------------
Thanks again to demolish, atom0s, and kjlotus. You guys helped me get this working, and I greatly GREATLY appreciate it.
Last edited by tagban on Sat Jan 10, 2015 8:14 pm, edited 11 times in total.

User avatar
demolish
Developer
Posts: 262
Joined: Thu Jul 26, 2012 7:12 am

Re: Custom PrintToPlayer/PrintToServer Stuff

Post by demolish » Tue Dec 30, 2014 6:09 pm

would be a good idea to have the colour as a parameter, instead of multiple functions which essentially do the same thing
<Giblet[NewBrain]> kj with this first step would be fine on my shit
Click here for a guide on scripting missions.

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Custom PrintToPlayer/PrintToServer Stuff

Post by kjLotus » Tue Dec 30, 2014 6:54 pm

by the way, "god" is unity chat

User avatar
tagban
Posts: 352
Joined: Fri Dec 28, 2012 11:31 am
Location: Pennsylvania, USA

Re: Custom PrintToPlayer/PrintToServer Stuff

Post by tagban » Tue Dec 30, 2014 6:59 pm

kjLotus wrote:by the way, "god" is unity chat
Updated for you. :)

User avatar
atom0s
Developer
Posts: 537
Joined: Thu Oct 25, 2012 9:52 am

Re: Custom PrintToPlayer/PrintToServer Stuff

Post by atom0s » Tue Dec 30, 2014 9:30 pm

The better way to handle this would be to allow an optional parameter as the chat type instead of having about 16 functions to do the same thing.

User avatar
TeoTwawki
Developer
Posts: 527
Joined: Mon Jul 15, 2013 9:50 pm

Re: Custom PrintToPlayer/PrintToServer Stuff

Post by TeoTwawki » Wed Dec 31, 2014 1:36 am

Nice! I have a bunch of custom non retail stuff I want to switch to using this now.

The param thing is a good idea...I should do that to the spoof messages thing too.
Hi, I run The Demiurge server.


Image
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding
PLS USE [ code ] CODE TAGS [ /code ] WHEN POSTING CODE
DO NOT PRIVATE MESSAGE ME ABOUT BUGS

User avatar
tagban
Posts: 352
Joined: Fri Dec 28, 2012 11:31 am
Location: Pennsylvania, USA

Re: Custom PrintToPlayer/PrintToServer Stuff

Post by tagban » Thu Jan 01, 2015 7:24 pm

please delete this post, no longer relevant. Updated main post.
Last edited by tagban on Fri Jan 02, 2015 9:56 pm, edited 1 time in total.

User avatar
tagban
Posts: 352
Joined: Fri Dec 28, 2012 11:31 am
Location: Pennsylvania, USA

Re: Custom PrintToPlayer/PrintToServer Stuff

Post by tagban » Fri Jan 02, 2015 9:54 pm

Possible Chat Colors List per atom0s's post under Resources:

Code: Select all

case 0:     // say
case 1:     // shout
case 8:     // emote
case 0x1A:  // yell
case 3:     // tell
case 4:     // party
case 5:     // linkshell
case 0x1B:  // linkshell (possibly new ls1)
case 0x1E:  // linkshell (possibly new ls2)
case 0x21:  // Unknown Message: {[GM] Atomos} This is a test message. (color was yellow/gold)
case 0x18:  // Unknown (Looks similar to say.)
case 0x19:  // Unknown (Looks similar to say.)
case 6:     // System Message 
case 7:     // System Message
case 0xC:   // GM Tell
case 0x15:  // Unknown (Strips name, shows just the message.) (color was yellow/gold)
case 0xD:   // Unknown (Strips name, shows just the message.) (color was same as say)
case 0xE:   // Unknown (Strips name, shows just the message.) (color was same as shout)
case 0x10:  // Unknown (Strips name, shows just the message.) (color was same as linkshell)
case 0x13:  // Unknown (Strips name, shows just the message.) (color was yellow)
case 0x16:  // Unknown (Strips name, shows just the message.) (color was yellow)
case 0x1C:  // Unknown (Strips name, shows just the message.) (color was green)
case 0x1F:  // Unknown (Strips name, shows just the message.) (color was yellow)
case 0xF:   // Unknown (Strips name, shows just the message.) (color was same as party)
case 0x11:  // Unknown (Strips name, shows just the message.) (color was yellow)
case 0x12:  // Unknown (Strips name, shows just the message.) (color was yellow)
case 0x14:  // Unknown (Strips name, shows just the message.) (color was yellow)
case 0x17:  // Unknown (Strips name, shows just the message.) (color was yellow)
case 0x1D:  // Unknown (Strips name, shows just the message.) (color was yellow)
case 0x20:  // Unknown (Strips name, shows just the message.) (color was yellow)
case 9:     // Do nothing.. packet is swallowed.
case 0xA:   // Do nothing.. packet is swallowed.
case 0xB:   // Do nothing.. packet is swallowed.
The GMTell one is interesting, I want to see what else can be done with that one, the "unknown ones" with yellow, are ALL the same color, nothing special. So I am not mapping them into my status.lua file. Will include that in next post.
--------------
I was reminded of some other cool things you can do with this, such as making NPC's say things that aren't scripted..
Make Cid appear to have hacked the player's linkshell...

Code: Select all

player:PrintToPlayer("[1] <Cid> Muah ha ha ha ha ha!! I'm in your LS chattin ur thingz", 0x10);
Or just something more simple:

Code: Select all

player:PrintToPlayer("<Cid> Servers that share, are servers that care.", 0xD);
Which will appear as "Say" chat coming from Cid. Is it perfect? No.. But pretty damn awesome. :)

User avatar
atom0s
Developer
Posts: 537
Joined: Thu Oct 25, 2012 9:52 am

Re: Custom PrintToPlayer/PrintToServer Stuff

Post by atom0s » Fri Jan 02, 2015 10:11 pm

The GM tell one is fairly basic, and is not really meant to be used for anything other then testing if a person is actively playing or botting. The tell has to be formatted in a special manner in the packet for it to work as well. When the user selects an option from the dialog, the game automatically sends a whisper back to the GM (without the client knowing) stating what option they choose. It's not something that can really be used to automate anything without manually parsing the response since its sent back as a tell to the GM too.

User avatar
tagban
Posts: 352
Joined: Fri Dec 28, 2012 11:31 am
Location: Pennsylvania, USA

Re: Custom PrintToPlayer/PrintToServer Stuff

Post by tagban » Fri Jan 02, 2015 10:51 pm

Thats awesome.. Also, updated PrintToServer to use Message Server to allow for multi-hosted game servers.

Post Reply