[C++] CodeBox Npc menu

User Tag List

Results 1 to 8 of 8
  1. #1
    mager1794's Avatar Member
    Reputation
    356
    Join Date
    Feb 2008
    Posts
    703
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [C++] CodeBox Npc

    CodeBox Npc

    This script was inspired by stoneharry's CodeBox Npc script he did in lua, i saw that he had like 6 possible options that you could use, and i felt sometimes its just not enough, and to add more to the lua you'd be doing alot of recoding of it.

    so i wrote this script

    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    
    #ifdef WIN32
    #pragma warning(disable:4305)
    #endif
    
    #define NPC 55555
    
    
    /*
    ##############################
    #######Fully Aware This ######
    #######Code isn't very  ######
    #######Efficient, but it######
    #######was a shot       ######
    ##############################
    ##############################
    ##########Created By##########
    ##########Mager1794 ##########
    ##############################
    */
    
    
    class SCRIPT_DECL CodeBox : public GossipScript
    {
    
    public:
        void GossipHello(Object * pObject, Player* Plr, bool AutoSend);
        void GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code);
        void GossipEnd(Object * pObject, Player* Plr);
        void Destroy()
        {
            delete this;
        }
        struct CodeBoxes;
    };
    struct CodeBox::CodeBoxes
    {
        const char * OptionText; //String for gossip to display
        string EntryCode;            //Code to enter for reward
        uint32 ItemId;            //Item Id for reward
    };
    
    
    void CodeBox::GossipHello(Object * pObject, Player* Plr, bool AutoSend)
        {
            GossipMenu *Menu;
            Menu->AddItem(10, "I would like to enter a code for a reward", 2, 1);
            if(AutoSend)
                Menu->SendTo(Plr);
        }
    
    void CodeBox::GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code)
    {
            //Define your code box information
            ///How many code boxes you want
            //CodeBoxes CodeBox[2];//must be equal to int codes below
            CodeBoxes CodeBox[2];
            int codes = 2;//must be equal to integer inside brackets
            //Define Code Options 1- ect.
            CodeBox[1].OptionText = "Test1";
            CodeBox[1].EntryCode = "1Test";
            CodeBox[1].ItemId = 22253;
            CodeBox[2].OptionText = "Test2";
            CodeBox[2].EntryCode = "2Test";
            CodeBox[2].ItemId = 4325;
    
            bool AutoSend = true;
    
            GossipMenu *Menu;
            
            switch(IntId)
            {
            case 0:
            GossipHello(pObject, Plr, true);
            break;
    
            case 1:
            {
            for(int i=1;i<codes;i++)
            {   
                    if(Code == CodeBox[i].EntryCode)
                    {
                        Item * item = objmgr.CreateItem(CodeBox[i].ItemId, Plr);
                        Plr->GetItemInterface()->AddItemToFreeSlot(item);
                    }
                }
            }break;
    
            case 2:
                {
                    for(int i=0;i<codes;i++)
                    {
                        Menu->AddItem(10, CodeBox[i].OptionText, i, 1);
                    }
                }break;
            }
    }
    
    void CodeBox::GossipEnd(Object * pObject, Player* Plr)
    {
        GossipScript::GossipEnd(pObject, Plr);
    }
    
    void SetupCode(ScriptMgr * mgr)
    {
        GossipScript * gs = (GossipScript*) new CodeBox();
        mgr->register_gossip_script(NPC, gs);
    }

    How to Use


    first off just use the find method and search for
    //Define Code Options 1- ect.

    you'll see

    Code:
            //Define Code Options 1- ect.
            CodeBox[1].OptionText = "Test1";
            CodeBox[1].EntryCode = "1Test";
            CodeBox[1].ItemId = 22253;
            CodeBox[2].OptionText = "Test2";
            CodeBox[2].EntryCode = "2Test";
            CodeBox[2].ItemId = 4325;
    

    now its simple to use how ever many Options you want on the gossip NPC just edit the number 2 for Code[2], to what ever number you choose
    and edit "codes = 2" to what ever number you choose.

    then just edit "Test1", to what ever and the "Test2"
    if you have more than 2, just hit Enter and type this

    Code[Number].OptionText = "MyMessage";

    also you have to edit the other values

    EntryCode = "The string they type in code box to gain reward"
    ItemId = the Id of the Item used as reward

    Database Version

    basically the same exact script only instead of using a structure i connected it to the database instead, enjoy

    A gm can make a 14 character long code to and then type it into the code box, and it will insert it into the database. The GM can then give the Player who earned the code, the code and he will enter it in, and it will seach database for the code, if not found then it doesn't work....

    this may be bugged i'm not sure but it might give all rewards.......

    C++ Script
    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    
    #ifdef WIN32
    #pragma warning(disable:4305)
    #endif
    
    #define NPC 55555
    
    
    /*
    ##############################
    #######Fully Aware This ######
    #######Code isn't very  ######
    #######Efficient, but it######
    #######was a shot       ######
    ##############################
    ##############################
    ##########Created By##########
    ##########Mager1794 ##########
    ##############################
    */
    
    
    class SCRIPT_DECL CodeBox : public GossipScript
    {
    
    public:
        void GossipHello(Object * pObject, Player* Plr, bool AutoSend);
        void GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code);
        void GossipEnd(Object * pObject, Player* Plr);
        void Destroy()
        {
            delete this;
        }
        struct CodeBoxes;
    };
    struct CodeBox::CodeBoxes
    {
        const char * OptionText; //String for gossip to display
        uint32 ItemId;            //Item Id for reward
    };
    
    
    void CodeBox::GossipHello(Object * pObject, Player* Plr, bool AutoSend)
        {
            GossipMenu *Menu;
            Menu->AddItem(10, "I would like to enter a code for a reward", 2, 1);
            if(Plr->GetSession()->HasGMPermissions())
            {
            Menu->AddItem(2, "Add new Code Entry", 10, 1);
            }
            if(AutoSend)
                Menu->SendTo(Plr);
        }
    
    void CodeBox::GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code)
    {
            //Define your code box information
            ///How many code boxes you want
            //CodeBoxes CodeBox[2];//must be equal to int codes below
            CodeBoxes CodeBox[2];
            int codes = 2;//must be equal to integer inside brackets
            //Define Code Options 1- ect.
            CodeBox[1].OptionText = "Test1";
            CodeBox[1].ItemId = 22253;
            CodeBox[2].OptionText = "Test2";
            CodeBox[2].ItemId = 4325;
    
    
    
            bool AutoSend = true;
    
            GossipMenu *Menu;
            
            switch(IntId)
            {
            case 0:
            //GossipHello(pObject, Plr, true);
            Menu->AddItem(10, "I would like to enter a code for a reward", 2, 1);
            if(AutoSend)
                Menu->SendTo(Plr);
            break;
    
            case 1:
            {
                
            for(int i=1;i<codes;i++)
            {     
                QueryResult * qres = WorldDatabase.Query("SELECT * FROM entry_codes WHERE code = '%s'", Code);
                    if(!qres == NULL)
                    {
                        Item * item = objmgr.CreateItem(CodeBox[i].ItemId, Plr);
                        Plr->GetItemInterface()->AddItemToFreeSlot(item);
                        WorldDatabase.Query("DELETE * FROM entry_codes WHERE code = '%s'", Code);
                    }
                    else
                    {
                        Plr->BroadcastMessage("Incorrect Code");
                }
            }break;
    
            case 2:
                {
                    for(int i=0;i<codes;i++)
                    {
                        Menu->AddItem(10, CodeBox[i].OptionText, i, 1);
                    }
                }break;
            case 10:
                {
                    int length;
                    length = strlen(Code);
                    if(length == 14)
                    {
                    WorldDatabase.Query("INSERT INTO `entry_codes` VALUES ('%s')", Code);
                    }
                    else
                    {
                        Plr->BroadcastMessage("Code entry must be 14 characters long");
                    }
                }
            }
            }
    }
    
    
    void CodeBox::GossipEnd(Object * pObject, Player* Plr)
    {
        GossipScript::GossipEnd(pObject, Plr);
    }
    
    void SetupCode(ScriptMgr * mgr)
    {
        GossipScript * gs = (GossipScript*) new CodeBox();
        mgr->register_gossip_script(NPC, gs);
    }

    SQL


    Code:
    USE 'world';
    CREATE TABLE "entry_codes" (
      "code" char(14) NOT NULL,
      UNIQUE KEY "code" ("code")
    );


    this script is untested please leave feed back if it doesn't work so i can fix it
    Last edited by mager1794; 06-01-2009 at 03:07 PM. Reason: made script better
    Lunar Gaming - Reaching For The Stars

    [C++] CodeBox Npc
  2. #2
    Choices's Avatar Member
    Reputation
    94
    Join Date
    Apr 2008
    Posts
    231
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i see you fixed that error after i passed out and went to bed :P Good Release man +rep

  3. #3
    Claiver's Avatar Member
    Reputation
    138
    Join Date
    Mar 2009
    Posts
    217
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kind of the same what I done back then, but GuaEngine wasn't released yet at that moment, so had no DB availability back then :/.

    Non the less +Rep for the contribution !
    Edit: Cooldown :/

  4. #4
    squizit's Avatar Member
    Reputation
    1
    Join Date
    Jan 2009
    Posts
    20
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i will use it. very nice ty for sharing+Rep

  5. #5
    Link_S's Avatar Member
    Reputation
    125
    Join Date
    Dec 2008
    Posts
    293
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's far more better than the first one, +Rep. But consider to use
    Code:
    if(qres != NULL)
    instead of
    Code:
    if(!qres == NULL)
    Why do I need a signature?

  6. #6
    Link_S's Avatar Member
    Reputation
    125
    Join Date
    Dec 2008
    Posts
    293
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something wierd happened, dubble post :S
    Why do I need a signature?

  7. #7
    insignia96's Avatar Banned
    Reputation
    33
    Join Date
    Oct 2008
    Posts
    304
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you rewrite this for aspire HS? I cant get all the pointers to change!

  8. #8
    Claiver's Avatar Member
    Reputation
    138
    Join Date
    Mar 2009
    Posts
    217
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Question: Is there someting similar to the 'for k,v in pairs(tablename) do' in c++? That's very handy and was wondering this.

Similar Threads

  1. Make Alliance NPCs kill Alliance in IF
    By Cloud in forum World of Warcraft Exploits
    Replies: 27
    Last Post: 08-23-2006, 11:52 AM
  2. Kill your own factions NPC's
    By Matt in forum World of Warcraft Exploits
    Replies: 9
    Last Post: 08-18-2006, 04:05 PM
  3. Make NPC Guards Mad!
    By Tbone in forum World of Warcraft Exploits
    Replies: 19
    Last Post: 07-14-2006, 10:34 PM
  4. Bug the AD NPC's in IF
    By KuRIoS in forum World of Warcraft Exploits
    Replies: 3
    Last Post: 06-30-2006, 07:57 PM
  5. Attack your own NPC's
    By oninuva in forum World of Warcraft Guides
    Replies: 0
    Last Post: 04-23-2006, 02:24 PM
All times are GMT -5. The time now is 07:46 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search