World chat /o ?

Hello, I tried setting up a world chat c++ script for my server but it crashes when someone on the server uses /o (Both admins and regular players.). I wrote it by looking at some other world scripts on different websites and they look a lot like the others ones so I don’t know if I can get help here or not… If I can’t, please delete my thread.

Here’s the code:

case CHAT_MSG_OFFICER:
{
char message[1024];
switch(GetPlayer()->GetSession()->GetSecurity())
{
case SEC_PLAYER: // normal player, non-vip
snprintf(message, 1024, “|cffFF0000[Alliance]|cffFFFF00[%s]:|cffffffff %s”, GetPlayer()->GetName(), msg.c_str());
break;

case 1: // Moderator
snprintf(message, 1024, “|cff01DF74[Mod]|cffFFFF00[%s]:|cffffffff %s”, GetPlayer()->GetName(), msg.c_str());
break;

case 2: // GameMaster
if (GetPlayer()->GetTeam()==ALLIANCE)
snprintf(message, 1024, “|cFF87CEFA[GameMaster]|cffFFFF00[%s]:|cffffffff %s”, GetPlayer()->GetName(), msg.c_str());
break;

case 3: //Admin
snprintf(message, 1024, “|cFFFF0000[Admin]|cffFFFF00[%s]:|cffffffff %s”, GetPlayer()->GetName(), msg.c_str());
break;

}
sWorld->SendGlobalText(message, NULL);
}
break;

From what I’ve seen on the other scripts it should work, and chathandler.cpp is the only file the other scripts have edited…

Let it filter the messages - check e.g. OutFatal or similar and check how it filters. Test and repeat.

I dont like the code : |

But the solution to the crash is that GetName probably changed to return a string and it should be char string in sprintf.

Change GetPlayer()->GetName() to GetPlayer()->GetName().c_str()

It would also be good to add a default case to the switch, just incase.

Next time, include a crashlog please.

GMs can only talk if they are alliance? I think you not only have the code mixed up, but, have no idea what you are doing with c++, so, maybe you should start with some “learn c++” websites before tackling TC coding.