Forum > Serverside Modding

[C++] Trinity Announce System

<< < (4/5) > >>

Everon Mightbane:
Meh. Well that sucks. Thanks anyway.

Everon Mightbane:
Sorry for double posting, but could someone take a look at this and tell me why its not working, it compiles just fine, however when I use .announce my worldserver.exe crashes.: [spoiler:2mi2ysll]
--- Code: ---#include "Chat.h"
#include "ScriptPCH.h"
class ann_commandscript : public CommandScript
{
public:
    ann_commandscript() : CommandScript("ann_commandscript") { }
    ChatCommand* GetCommands() const
    {
        static ChatCommand commandTable[] =
        {
            { "announce",                              SEC_PLAYER,  true, &HandleAnnounceCommand,                                  "", NULL },
{ NULL,                                             0, false, NULL,                                                    "", NULL }
        };
        return commandTable;
    };
static bool HandleAnnounceCommand(ChatHandler* handler, const char* args)
{
    std::string rank("");
    uint32 gmlevel;
    WorldPacket data;
    std::string name("Console");
    if (WorldSession* session = handler->GetSession())
    {
Player* player = session->GetPlayer();
gmlevel = player->GetSession()->GetSecurity();
    switch (gmlevel)
{
    case 0:
      rank = "|cff0051FFPlayer|r"; break;
    case 1:
      rank = "|cff88DC51Voter|r"; break;
    case 2:
      rank = "|cffF28A00Donator|r"; break;
    case 3:
      rank = "|cffAD01B0Moderator|r"; break;
  case 4:
      rank = "|cffAD01B0Administrator|r"; break;
}  
    }
   
    if (!*args)
        return false;
    if (WorldSession* session = handler->GetSession())
        name = session->GetPlayer()->GetName();
    sWorld->SendWorldText(LANG_CUSTOM_ANNOUNCE, rank, name, args);
    return true;
    }
};
void AddSC_ann_commandscript()
{
    new ann_commandscript();
};
--- End code ---
[/spoiler:2mi2ysll]

LANG_CUSTOM_ANNOUNCE is linked up in language.h and has the correct reference in my trinity_string table and the script compiles without issue.

Steff:
Please use pastbin!

schlumpf:
Player* player = session->GetPlayer();
> Not checked for player == NULL.
   gmlevel = player->GetSession()->GetSecurity();
> Not checked for GetSessin() == NULL, also this should be the same as session already retrieved earlier.
    if (!*args)
> You should check that right away on the top, before doing anything else.
    if (WorldSession* session = handler->GetSession())
        name = session->GetPlayer()->GetName();
> You're getting the session another time. Also, not checking for player being NULL.
    sWorld->SendWorldText(LANG_CUSTOM_ANNOUNCE, rank, name, args);
> sWorld is NULL? Idk.

Everon Mightbane:
Still not working heres my updated code: http://pastebin.com/FV1rtUP7

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version