[Release][C++]Guess the Number menu

User Tag List

Results 1 to 4 of 4
  1. #1
    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)

    [Release][C++]Guess the Number

    Guess Some.

    This is a challenging npc that's testing your nerves. The npc generate a random number between 0-9, if you break the number on your one chance shot, you gain 500g.

    I made these out of my freetime, enjoy.

    Code:
    /*
        Guesser NPC
        Made by Link_S of MMOwned.
    
            Brief Description:
                    You have one chance on you to guess an random generated number. If you guess right, gold is received.
    */
    
    #include "StdAfx.h"
    
    #define NPCID 0 //<<<<---- Set this. Otherwise it won't work!
    map<Player*, int> numbers;
    typedef pair<Player*, int> Pairs;
    
    class GuessNumberNPC : public GossipScript
    {
    public:
        void GossipHello(Object * pObject, Player* plr, bool AutoSend)
        {
            GossipMenu *menu;
            objmgr.CreateGossipMenuForPlayer(&menu, pObject->GetGUID(), 1, plr);
    
            menu->AddItem(0, "I'm thinking about a number between 0-9. Do you think you can break it. If you try me again, I change the number to another.", 999);
            menu->AddItem(0, "I can easiely break it.", 11);
            menu->AddItem(0, "I don't dare to.", 22);
     
            if(AutoSend)
               menu->SendTo(plr);
        };
    
        void GossipSelectOption(Object * pObject, Player* plr, uint32 id, uint32 intId, const char * code)
        {
            switch(intId)
            {
            case 11:
                {
                    GossipMenu *menu;
                    objmgr.CreateGossipMenuForPlayer(&menu, pObject->GetGUID(), 1, plr);
                    //We don't want the user to enter the options, make it easier for them and list them as menu options.
                    for(int i = 0; i < 9; i++)
                    {
                        char text[20];
                        snprintf(text, 20, "%s", i);
                        menu->AddItem(0, text, i);
                    }
                    int random = rand()%9;
                    numbers.insert(Pairs(plr, random));
                    menu->SendTo(plr);
                }break;
            case 22:
                static_cast<Creature*>(pObject)->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "Such a coward.");
                plr->Gossip_Complete();
                break;
            default:
                {
                    for(map<Player*, int>::iterator itr = numbers.begin(); itr != numbers.end(); itr++)
                    {
                        if(itr->first == plr)
                        {
                            if(intId == itr->second)
                            {
                                plr->SendAreaTriggerMessage("Good, that's the right number.");
                                plr->BroadcastMessage("Good, that's the right number.");
                                //Give the player 5g as an reward.
                                plr->SetUInt32Value(PLAYER_FIELD_COINAGE, (plr->GetUInt32Value(PLAYER_FIELD_COINAGE) + (500 * 10000)));
                                numbers.erase(itr);
                            }
                            else
                            {
                                plr->SendAreaTriggerMessage("Wrong number, try again.");
                                plr->BroadcastMessage("Wrong number, try again.");
                                GossipHello(pObject, plr, true);
                            }
                        }
                    }
                }break;
            }
        };
     
        void Destroy()
        {
            delete this;
        };
    };
    
    void SetupGuessNumberNPC(ScriptMgr * mgr)
    {
        mgr->register_gossip_script(NPCID, (GossipScript*)new GuessNumberNPC());
    }
    NOTE: I haven't got the opportunity to test this.
    Why do I need a signature?

    [Release][C++]Guess the Number
  2. #2
    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)
    Very simple yet funny. Wouldn't use this myself though.
    +Rep anyways .

  3. #3
    LaAevie's Avatar Member
    Reputation
    85
    Join Date
    Mar 2008
    Posts
    143
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This looks like a pretty neat C++ npc. will later, on cooldown.
    <3

  4. #4
    Reflection's Avatar Legendary
    Reputation
    783
    Join Date
    Mar 2008
    Posts
    3,377
    Thanks G/R
    1/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great contribution, Link. Keep it up.

    Freelance Digital Artist
    https://reflectionartwork.deviantart.com
    You did not desert me
    My brothers in arms


Similar Threads

  1. Guess the number and get 30 days gametime!
    By HighFred in forum Contests
    Replies: 18
    Last Post: 05-15-2013, 01:16 AM
  2. [READ/RELEASE] One of the best EMU-Devs arround and some of his work posted here!
    By latruwski in forum World of Warcraft Emulator Servers
    Replies: 7
    Last Post: 11-17-2007, 07:43 AM
  3. Increase the number of reports a user can make.
    By Remahlól in forum Suggestions
    Replies: 4
    Last Post: 11-12-2007, 09:02 AM
  4. [Script Release] Naxxramas - Noth the Plaguebringer
    By blukkiee in forum World of Warcraft Emulator Servers
    Replies: 1
    Last Post: 08-28-2007, 11:25 AM
All times are GMT -5. The time now is 02:23 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search