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

[SOLVED] adding my first script into trinitycore c++

Status
Not open for further replies.

brunolopes

Enthusiast
Hello guys yesterday i was able to put my trinitycore core running, and today i m trying to add my first c++ script i added the cpp file on the costume scripts folder at the source and then i used cmake and compiled it again and the server runned perfectly the thing is i don´t have wow 3.3.5a i m still downloading it but i m just to curious to know if the script is working so can you guys please tell me if i did everything well?

worldchat.cpp
Code:
/*
a simple chat system with an adjustable prefix. default`.chat`.
with adjustable color layout and adjustable channel name.
made by slp13at420 of EmuDevs.com
*/
#include "Chat.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "World.h"

std::string wc1_world_chat_command = "chat";
std::string wc1_channel_name = "World";

std::string wc1_TeamIcon[2] =
{
    "|TInterface\\icons\\Inv_Misc_Tournaments_banner_Human.png:13|t",
    "|TInterface\\icons\\Inv_Misc_Tournaments_banner_Orc.png:13|t"
};

std::string wc1_GM_ICON = "|TINTERFACE/CHATFRAME/UI-CHATICON-BLIZZ:13:13:0:-1|t";

std::string wc1_GM_RANK[6] =
{
    "Player",
    "GM1",
    "GM2",
    "GM3",
    "Lead GM",
    "Admin",
}; // if you have less/more ranks then -/+ as necessary. edit rank names as necessary.

std::string wc1_ClassIcon[11] =
{
    "|TInterface\\icons\\INV_Sword_27.png:13|t",
    "|TInterface\\icons\\INV_Hammer_01.png:13|t",
    "|TInterface\\icons\\INV_Weapon_Bow_07.png:13|t",
    "|TInterface\\icons\\INV_ThrowingKnife_04.png:13|t",
    "|TInterface\\icons\\INV_Staff_30.png:13|t",
    "|TInterface\\icons\\Spell_Deathknight_ClassIcon.png:13|t",
    "|TInterface\\icons\\inv_jewelry_talisman_04.png:13|t",
    "|TInterface\\icons\\INV_Staff_30.png:13|t",
    "|TInterface\\icons\\INV_Staff_30.png:13|t",
    "",
    "|TInterface\\icons\\Ability_Druid_Maul.png:13|t",
};

std::string wc1_allyblue = "|cff3399FF";
std::string wc1_hordered = "|cffCC0000";
std::string wc1_white = "|cffFFFFFF";
std::string wc1_green = "|cff00cc00";
std::string wc1_red = "|cffFF0000";
std::string wc1_blue = "|cff6666FF";
std::string wc1_black = "|cff000000";
std::string wc1_grey = "|cff808080";

std::string wc1_TeamColor[2] = { wc1_allyblue, wc1_hordered };

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

    void OnLogin(Player* player, bool /*firstLogin*/) override
    {
        ChatHandler(player->GetSession()).PSendSysMessage("type `.%s` for World Chat commands.", wc1_world_chat_command.c_str());
    }
};

class WORLD_CHAT : public CommandScript
{
public:
    WORLD_CHAT() : CommandScript("WORLD_CHAT") { }

    std::vector<ChatCommand> GetCommands() const
    {
        static std::vector<ChatCommand> commandTable =
        {
            { wc1_world_chat_command.c_str(), rbac::RBAC_IN_GRANTED_LIST, true, &HandleWorldChatCommand, "World Chat prefix. `.chat hello world`" },
        };
        return commandTable;
    }

    static bool HandleWorldChatCommand(ChatHandler* handler, const char* msg)
    {
        // here you can apply different colors
        std::string wc1_channelcolor = wc1_grey;
        std::string wc1_gm_rankcolor = wc1_blue;
        std::string wc1_msgcolor = wc1_green;

        WorldSession* session = handler->GetSession();
        Player* player = session->GetPlayer();
        auto gm_rank = session->GetSecurity();
        std::string pName = player->GetName();

        std::string name = "|Hplayer:" + pName + "|h" + pName;

        std::string WCMSG = "";

        WCMSG = "[" + wc1_channelcolor + wc1_channel_name + "|r]";
        WCMSG = WCMSG + "[" + wc1_TeamIcon[player->GetTeamId()] + "]";

        if (player->IsGameMaster())
        {

            WCMSG = WCMSG + "[" + wc1_GM_ICON + "]";
            WCMSG = WCMSG + "[" + wc1_gm_rankcolor + wc1_GM_RANK[gm_rank] + "|r]";
        }

        WCMSG = WCMSG + "[" + wc1_ClassIcon[player->getClass() - 1] + "]";
        WCMSG = WCMSG + "[" + wc1_TeamColor[player->GetTeamId()] + name + "|r]";
        WCMSG = WCMSG + ":" + wc1_msgcolor + msg;

        sWorld->SendGlobalText(WCMSG.c_str(), NULL);

        return true;
    }
};

void AddSC_WorldChat()
{
    new Player_WorldChat;
    new WORLD_CHAT;
}



custom_script_loader

Code:
/*
 * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

// This is where scripts' loading functions should be declared:


// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
    AddSC_WorldChat();    
}


thanks in advance!
 
Last edited by a moderator:

slp13at420

Mad Scientist
:somuchwin:
I'd recognize that work anywhere :)

did you add it to the script loader also?
src/server/game/scripting/ScriptLoader.cpp :
Code:
[COLOR="#808080"]
#ifdef SCRIPTS
/* This is where custom scripts' loading functions should be declared. */
	void AddSC_WorldChat();
#endif

void AddCustomScripts()
{
#ifdef SCRIPTS
    /* This is where custom scripts should be added. */
	AddSC_WorldChat();
#endif
[/COLOR]

this is at the very bottom of the file.
 
Last edited:

brunolopes

Enthusiast
So it should look like this?
Code:
 * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

// This is where scripts' loading functions should be declared:
void AddSC_WorldChat();
#endif

void AddCustomScripts()
{
#ifdef SCRIPTS
    /* This is where custom scripts should be added. */
	AddSC_WorldChat();
#endif

// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
	AddSC_WorldChat();	
}



ps: how can i make code tags? sorry xD
 

brunolopes

Enthusiast
adding my second c++ script to trinitycore

I have added my first c++ script to my core but now we the second i really don´t know what i m doing wrong can some one help me?

Tools_NPC.cpp
End of the script
Code:
void AddSC_Tools_NPC()
{
new Tools_NPC();
}	

custom_script_loader


// This is where scripts' loading functions should be declared:
void AddSC_WorldChat_Commanded();
void AddSC_Tools_NPC();

// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
AddSC_WorldChat_Commanded();
AddSC_Tools_NPC();	
}
 

slp13at420

Mad Scientist
Like This:
Code:
[COLOR="#808080"]
#ifdef SCRIPTS
/* This is where custom scripts' loading functions should be declared. */
	void AddSC_WorldChat();
#endif

void AddCustomScripts()
{
#ifdef SCRIPTS
    /* This is where custom scripts should be added. */
	AddSC_WorldChat();
#endif
}
[/COLOR]



code tags button is found in the reply tools when in advanced mode , annotated by a pound sign `#`:
[ CODE ]
blah blah blah code ...
[ / CODE ]

would produce:
Code:
blah blah blah code ...
 
Last edited:

Tommy

Founder
Merged your other thread into this one.

You don't need the scripts definition and I think they got rid of that regardless. [MENTION=1862]brunolopes[/MENTION]: The only thing you missed was the function declaration.

Code:
/*
 * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

// This is where scripts' loading functions should be declared:
[COLOR="#00FF00"]void AddSC_WorldChat();[/COLOR]


// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
    [COLOR="#00FF00"]AddSC_WorldChat();[/COLOR]
}

Remember, you can look at existing script loaders for examples.

I have added my first c++ script to my core but now we the second i really don´t know what i m doing wrong can some one help me?

Tools_NPC.cpp
End of the script
Code:
void AddSC_Tools_NPC()
{
new Tools_NPC();
}	

custom_script_loader


// This is where scripts' loading functions should be declared:
void AddSC_WorldChat_Commanded();
void AddSC_Tools_NPC();

// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
AddSC_WorldChat_Commanded();
AddSC_Tools_NPC();	
}

What exactly is the issue here? Are you getting any particular errors?
 

brunolopes

Enthusiast
Well now i m able to add c++ scripts to my server thanks! my only problem is there aint many c++ scripts updated to the latest revision and every other source besides the newest updated source from trinity gives me errors on visual studio and wont finish compile so i m not quite sure how to fix this, since i don´t know how to modify scripts i tryed to compile a older source i tryed emudevs 3.3.5a source from github i tryed community source i tryed some other sources that i also found on github so dunno i cant compile a older revision nor can update scripts i m dommed
 
Status
Not open for further replies.
Top