Welcome to AC Web.
Results 1 to 11 of 11

Thread: Buff Command

  1. #1

    Buff Command

    Found original script here https://www.ac-web.org/forums/showth...f-command-help and updated it to work with TrinityCore rev. 4b309f7ee558+

    Script copies shell from cs_cast.cpp and modifies methods used by it pretty much. If you have any problems with your specific revision of TrinityCore then just copy the shell from cs_cast.cpp and modify the handler so it matches mine, or something similar. Enjoy!

    Thanks to Alistar for constructive criticism.

    Code:
    /* ScriptData
    Name: cs_buff
    %Complete: 100
    Comment: Custom buff command.
    Created by unknown, updated by MrSolid.
    Tested with TrinityCore rev. 4b309f7ee558+
    Category: commandscripts
    EndScriptData */
    
    #include "Chat.h"
    #include "RBAC.h"
    #include "WorldSession.h"
    
    using namespace Trinity::ChatCommands;
    
    class buff_commandscript : public CommandScript
    {
    public:
        buff_commandscript() : CommandScript("buff_commandscript") { }
    
        ChatCommandTable GetCommands() const override
        {
            static ChatCommandTable commandTable =
            {
                { "buff",   HandleBuffCommand,      rbac::RBAC_ROLE_PLAYER,              Console::No },
            };
            return commandTable;
        }
    
        static bool HandleBuffCommand(ChatHandler* handler, const char* /**/)
        {
            Player* player = handler->GetSession()->GetPlayer();
    
            if (player->InArena())
                player->GetSession()->SendNotification("You can't use that item in an arena match!");
            else
            {
                player->RemoveAurasByType(SPELL_AURA_MOUNTED);              
                for (int i = 0; i < (sizeof(m_Auras) / sizeof(m_Auras[0])); i++)
                    player->AddAura(m_Auras[i], player);
                handler->PSendSysMessage("|cffB400B4You have been buffed, enjoy!");
            }
    
            return true;
        }
    private:
        static constexpr std::array<uint32, 7> m_Auras{ 48162, 48074, 48170, 43223, 36880, 467, 48469 };
    };
    
    void AddSC_buff_commandscript()
    {
        new buff_commandscript();
    }
    Last edited by MrSolid; 08-06-2022 at 09:28 AM. Reason: Script now uses fixed std::array

  2. #2
    Looks good. I just don't see a reason to use a vector or a index based loop here.

  3. #3
    Quote Originally Posted by Alistar View Post
    Looks good. I just don't see a reason to use a vector or a index based loop here.
    I just copied the script functionality from the post I linked, anyways I used a vector since it's not fixed size. I also changed the for loop so that it loops till the end of the auras array, this way future proofing it somewhat when someone wants to add their own aura to the list.

    EDIT: I've commented out my old method if anyone still wants to go ahead and use it, I've changed it to use a fixed array size now so it should be more memory efficient, thanks Alistar for the suggestion.

    Quote Originally Posted by wormen View Post
    Hi not worked :/
    Can you share what error you got? And what version of TrinityCore are you using?
    Last edited by MrSolid; 08-06-2022 at 08:30 AM.

  4. #4
    error

    /TrinityCore/src/server/scripts/Custom/buff.cpp:15:5: error: unknown type name 'ChatCommandTable'; did you mean 'ChatCommand'?
    ChatCommandTable GetCommands() const override
    ^~~~~~~~~~~~~~~~
    ChatCommand
    /TrinityCore/src/server/game/Chat/ChatCommands/ChatCommand.h:213:19: note: 'ChatCommand' declared here
    class TC_GAME_API ChatCommand
    ^
    /TrinityCore/src/server/scripts/Custom/buff.cpp:15:22: error: virtual function 'GetCommands' has a different return type ('ChatCommand') than the function it overrides (which has return type 'std::vector<ChatCommand>')
    ChatCommandTable GetCommands() const override
    ~~~~~~~~~~~~~~~~ ^

  5. #5
    Quote Originally Posted by wormen View Post
    error
    Maybe #include "ChatCommand.h"


    Quote Originally Posted by MrSolid View Post
    I just copied the script functionality from the post I linked, anyways I used a vector since it's not fixed size. I also changed the for loop so that it loops till the end of the auras array, this way future proofing it somewhat when someone wants to add their own aura to the list.

    EDIT: I've commented out my old method if anyone still wants to go ahead and use it, I've changed it to use a fixed array size now so it should be more memory efficient, thanks Alistar for the suggestion.



    Can you share what error you got? And what version of TrinityCore are you using?
    Good job. If I could give some constructive criticism. In C++ there's a library called <array> it's a good habbit to use that instead of using C style arrays.

    Using foreach instead of a index loop is good if we don't have any use of the index.

    Also limiting the scope of our variables is good practice too moving the array inside the class is a good idea.



  6. #6
    Quote Originally Posted by Alistar View Post
    Good job. If I could give some constructive criticism. In C++ there's a library called <array> it's a good habbit to use that instead of using C style arrays.

    Using foreach instead of a index loop is good if we don't have any use of the index.

    Also limiting the scope of our variables is good practice too moving the array inside the class is a good idea.

    Hi, I've updated the script with your advice, thanks for the constructive criticism

    - - - Updated - - -

    Quote Originally Posted by wormen View Post
    error
    You're using an old version of TC since you're getting an error for ChatCommandTable. Take a look at one of the existing command scripts within TC like cs_cast.cpp and duplicate it. Replace the command handler with the buff handler and you're done.

    The last message of this post also uses ChatCommand instead of ChatCommandTable, might be worth just taking a look at that: https://www.ac-web.org/forums/showth...f-command-help

    Latest core has this comment about ChatCommand
    Code:
    // backwards compatibility with old patches
    using ChatCommand [[deprecated("std::vector<ChatCommand> should be ChatCommandTable! (using namespace Trinity::ChatCommands)")]] = Trinity::ChatCommands::ChatCommandBuilder;
    Last edited by MrSolid; 08-06-2022 at 09:37 AM.

  7. #7
    Great, great. Glad to see life in AC

  8. #8
    in game not worked command

  9. #9
    Awesome release +rep

  10. #10
    Awesome work and share +rep

  11. #11
    Awesome work and share +rep

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •