yvoms

Honor Gambler!

Nov 5th, 2014
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. /* Honor Gamble script Created by yvoms 5-11-2014
  2.    This is just a very simple gamble script where an user inputs an amount of honor and has chance on doubling the amount.
  3.  */
  4. #pragma warning(disable:4146)
  5. #define HONOR 43308
  6.  
  7. class gamble_npc : public CreatureScript
  8. {
  9. public:
  10.     gamble_npc() : CreatureScript("gamble_npc") { }
  11.  
  12.     bool OnGossipHello(Player * player, Creature * creature)
  13.     {
  14.  
  15.         player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to play!", GOSSIP_SENDER_MAIN, HONOR, "Insert amount of Honor", 0, true);
  16.         player->ADD_GOSSIP_ITEM(3, "How does this Game work?", GOSSIP_SENDER_MAIN, 0);
  17.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  18.         return true;
  19.     }
  20.  
  21.     bool OnGossipSelect(Player * player, Creature * creature, uint32 sender, uint32 uiAction)
  22.     {
  23.         player->PlayerTalkClass->ClearMenus();
  24.  
  25.         if(uiAction == 0)
  26.         {
  27.             // Check this later on
  28.             player->ADD_GOSSIP_ITEM(7, "Back..", GOSSIP_SENDER_MAIN, 1);
  29.             player->SEND_GOSSIP_MENU(123432, creature->GetGUID());
  30.         }
  31.         else if(uiAction == 1)
  32.         {  
  33.             OnGossipHello(player, creature);
  34.         }
  35.         else if(uiAction == 2)
  36.         {
  37.             player->CLOSE_GOSSIP_MENU();
  38.         }
  39.         return true;
  40.     }
  41.  
  42.     bool OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 uiAction, const char* code)
  43.     {
  44.         player->PlayerTalkClass->ClearMenus();
  45.         uint32 amount = 0;
  46.         amount = uint32(atol(code));
  47.  
  48.         if(amount < 1 || !player->HasItemCount(uiAction, amount, false))
  49.         {
  50.             player->GetSession()->SendNotification("Invalid amount inserted");
  51.         }
  52.         else
  53.         {
  54.             if(urand(1,2) == 1)
  55.             {
  56.                 GiveItemAmount(player, uiAction, amount);
  57.             }
  58.             else
  59.             {
  60.                 player->DestroyItemCount(uiAction, amount, true);
  61.             }
  62.         }
  63.         OnGossipSelect(player, creature, sender, 0);
  64.         return true;
  65.     }
  66.  
  67.     // You CAN ignore this whole thing.
  68.     bool GiveItemAmount(Player * player, uint32 itemEntry, uint32 amount)
  69.     {
  70.         if (amount < 0)
  71.         {
  72.             player->DestroyItemCount(itemEntry, -amount, true, false);
  73.             return true;
  74.         }
  75.         if (amount == 0)
  76.             amount = 1;
  77.  
  78.         uint32 noSpaceForCount = 0;
  79.  
  80.         ItemPosCountVec dest;
  81.         uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemEntry, amount, &noSpaceForCount);
  82.  
  83.         if (msg != EQUIP_ERR_OK)
  84.             amount -= noSpaceForCount;
  85.  
  86.         if (amount == 0 || dest.empty())
  87.             return false;
  88.  
  89.         Item* item = player->StoreNewItem(dest, itemEntry, true, Item::GenerateItemRandomPropertyId(itemEntry));
  90.         return true;
  91.     }
  92. };
  93.  
  94. void AddSC_gamble_npc()
  95. {
  96.     new gamble_npc();
  97. }
Advertisement
Add Comment
Please, Sign In to add comment