• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

TrinityCore-Multi Welcome Announcer OnLogin

Sylica

Exalted Member
Today I like to share a small script I made, while being bored programming class.

Its a simple function that welcomes new players on login to the world, then greets existing players on return to the world.

Code:
/*
 *  @script made by Sylica
 *  @project name: Project Firestorm
 */

#include "ScriptMgr.h"
#include "Player.h"
#include "Chat.h"

class welcome_player_message : public PlayerScript
{
public:
    welcome_player_message() : PlayerScript("welcome_player_message") { }

    void OnLogin(Player* player, bool firstLogin) override
    {
        std::ostringstream message;
        if (firstLogin)
        {
            message << "|cff3ADF00Please welcome " << player->GetName() << " to our server!|r";
            sWorld->SendGlobalText(message.str().c_str(), nullptr);
        }
        else 
        {
            message << "|cff3ADF00Glade to see you back " << player->GetName() << "!|r";
            ChatHandler(player->GetSession()).PSendSysMessage(message.str().c_str());
        }
    }
};

void AddSC_onlogin_announcer()
{
    new welcome_player_message();
}

Been getting questions on why 'nullptr' is erroring on compile. This script is originally for c++-11, where nullptr is supported. For older compiler, change 'nullptr' to 'NULL'.

Support:
Windows Support: MSVS 2012+
Linux Support: gcc & g++ 4.6.1/4.7.1
 
Last edited:

Sylica

Exalted Member
Why do you check if playtime < 2 instead of using the first login variable? :p

You can add a firstLogin function to the script, in most cases. This is checking for play time though. Since I made this my class project, got a lot of feed back on what to use. :p
 

Vitrex

Moderator
*Glad :D not glade
Thank you for release ! :)
And ye, first login variable would be more logical :)
 

Sylica

Exalted Member
*Glad :D not glade
Thank you for release ! :)
And ye, first login variable would be more logical :)

I have to agree on it, but for most projects I tested it on, it doesn't work since that function doesn't exist. :p I mean, they can change it that way if they want.
 

Vitrex

Moderator
the best would be to check how first login cinematic works and do it that way i think :)
But how you said, yea everyone is free to edit script how they wan't :)
 

Sylica

Exalted Member
the best would be to check how first login cinematic works and do it that way i think :)
But how you said, yea everyone is free to edit script how they wan't :)

It does use the same function, but cinematic is far from complete. Anyways, yes I do allow anyone to edit the script.

I might make more scripts to share over time.
 
Top