Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Gamble npc V1.0
- Created By yvoms for lostarmywow
- V1.0
- To do's:
- Make the Actual Gamble thing,
- Make it so they can enter their custom amount and 50% chanse on winning the double,
- Checking if they have the Amount they want to gamble with,
- Make a how does the game work gossip, with the textID from the database, SQL will be included.
- */
- #define SOULS 60000
- #define UNHOLY_BADGE 29424
- #define DAEMON_HEAD 60005
- class gamble_npc : public CreatureScript
- {
- public:
- gamble_npc() : CreatureScript("gamble_npc") { }
- bool OnGossipHello(Player * player, Creature * creature)
- {
- // Note how the uiActions are the item IDs
- player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to play with Souls!", GOSSIP_SENDER_MAIN, SOULS, "Insert amount of souls", 0, true);
- player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to play with Deamon Heads", GOSSIP_SENDER_MAIN, DAEMON_HEAD, "Insert amount of Deamon Heads", 0, true);
- player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to play with Unholy Badges!", GOSSIP_SENDER_MAIN, UNHOLY_BADGE, "Insert amount of Unholy Badges", 0, true);
- player->ADD_GOSSIP_ITEM(3, "How does this Game work?", GOSSIP_SENDER_MAIN, 0);
- // player->ADD_GOSSIP_ITEM(1, "Nevermind", GOSSIP_SENDER_MAIN, 1000); // Nevermind buttons are usually used when there is only one option in the menu, since if there is only one button, it is automatically clicked.
- player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
- return true;
- }
- bool OnGossipSelect(Player * player, Creature * creature, uint32 sender, uint32 uiAction) // happens when a normal gossip item is selected
- {
- player->PlayerTalkClass->ClearMenus();
- if(uiAction == 0)
- {
- // Check this later on
- player->ADD_GOSSIP_ITEM(7, "Back..", GOSSIP_SENDER_MAIN, 1);
- player->SEND_GOSSIP_MENU(123432, creature->GetGUID());
- }
- else if(uiAction == 1)
- {
- OnGossipHello(player, creature);
- }
- else if(uiAction == 2)
- {
- player->CLOSE_GOSSIP_MENU();
- }
- return true;
- }
- bool OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 uiAction, const char* code) // happens when an extended gossip item is selected and the code is set to true for the gossip item.
- {
- player->PlayerTalkClass->ClearMenus();
- // uiAction is the item ID
- uint32 amount = 0;
- amount = uint32(atol(code)); // atol tries to convert code (the inserted thing) into a number.
- if(amount < 1 || !player->HasItemCount(uiAction, amount, false)) // && means and, || means or
- {
- player->GetSession()->SendNotification("Invalid amount inserted");
- }
- else
- {
- if(urand(1,2) == 1) // pic a random number between 1 and 2 (50 % chance to get 1)
- {
- // won, add items
- // adding items is a bit more complicated than destroying them .. the player might not have enough space in bags etc.
- GiveItemAmount(player, uiAction, amount);
- }
- else
- {
- // lost, delete items
- player->DestroyItemCount(uiAction, amount, true);
- }
- }
- OnGossipSelect(player, creature, sender, 0); // Go to uiAction 0, aka show the selection menu again
- return true;
- }
- // You CAN ignore this whole thing for now .. all you need to know is that it adds the item to the player if he has space and returns true, if not enough space it returns false and doesnt add anything
- // this function is pretty much like .additem command. Existing code is very useful .. Whenever I try to do something, I try to remember if there is a command for it and look at it's code.
- bool GiveItemAmount(Player * player, uint32 itemEntry, uint32 amount)
- {
- if (amount < 0)
- {
- player->DestroyItemCount(itemEntry, -amount, true, false);
- return true;
- }
- if (amount == 0)
- amount = 1;
- uint32 noSpaceForCount = 0;
- ItemPosCountVec dest;
- uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemEntry, amount, &noSpaceForCount);
- if (msg != EQUIP_ERR_OK)
- amount -= noSpaceForCount;
- if (amount == 0 || dest.empty())
- return false;
- Item* item = player->StoreNewItem(dest, itemEntry, true, Item::GenerateItemRandomPropertyId(itemEntry));
- return true;
- }
- };
- void AddSC_gamble_npc()
- {
- new gamble_npc();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement