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

Simple Gambler Npc

Tommy

Founder
Hello, this is just a quick script I put together. Nothing fancy, I thought about replacing the gold value of (10000-100000), but I decided not to do that. Anyway, enjoy!
Features:
Simple gossip NPC script that randomizes from 0-4. Depending on the case, it will be a different win/lose value each time.


Patch:
3.3.5a
This can be converted to cataclysm (4.3.4-) very easily.



Source:
Gambler NPC - Pastebin
Gambler NPC - Paste2

EmuDevs:

Code:
/*
 *╔═╦═╦═╦╦╦══╦═╦╗─╔╦══╗ 
 *║╦╣║║║║║╠╗╗║╦╣╚╦╝║══╣
 *║╩╣║║║║║╠╩╝║╩╬╗║╔╬══║
 *╚═╩╩═╩╩═╩══╩═╝╚═╝╚══╝
 *            www.emudevs.com
*/
enum GoldVals
{
    GOLD_ONE = 10000,
    GOLD_THREE = 30000,
    GOLD_FIVE = 50000,
    GOLD_TEN = 100000,
};

class npc_gamble : public CreatureScript
{
public:
    npc_gamble() : CreatureScript("npc_gamble") { }

    bool OnGossipHello(Player* player, Creature* creature)
    {
        if (player->GetMoney() < GOLD_ONE)
        {
            player->GetSession()->SendNotification("You don't have enough gold!");
            return false;
        }

        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_VENDOR, "I would like to gamble gold [1g]", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, "Nevermind", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
        return true;
    }

    bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 actions)
    {
        player->PlayerTalkClass->ClearMenus();

        if (actions == GOSSIP_ACTION_INFO_DEF+1)
        {
            player->ModifyMoney(-GOLD_ONE);

            int32 moneyValue = 0;
            bool wonOrLost = false;

            switch(rand()%5)
            {
                case 0:
                    moneyValue = GOLD_ONE;
                    wonOrLost = false;
                    break;
                case 1:
                    moneyValue = GOLD_THREE;
                    wonOrLost = false;
                    break;
                case 2:
                    moneyValue = GOLD_TEN;
                    wonOrLost = true;
                    break;
                case 3:
                    moneyValue = GOLD_FIVE;
                    wonOrLost = false;
                    break;
                case 4:
                    moneyValue = GOLD_ONE;
                    wonOrLost = true;
                    break;
            }

            if (wonOrLost)
            {
                player->ModifyMoney(moneyValue);
                ChatHandler(player->GetSession()).PSendSysMessage("You won!");
            }
            else
            {
                if (player->HasEnoughMoney(moneyValue))
                {
                    player->ModifyMoney(-moneyValue);
                    ChatHandler(player->GetSession()).PSendSysMessage("You lost %i gold!", moneyValue);
                }
                else
                    ChatHandler(player->GetSession()).PSendSysMessage("You lost, but you don't have enough money to lose!");
            }
            player->CLOSE_GOSSIP_MENU();
        }
        else
            player->CLOSE_GOSSIP_MENU();
        return true;
    }
};

void AddSC_on_gamble()
{
    new npc_gamble;
}

ENJOY!

Again, very simple. :blabla:

 
Top