Advertisement
Rochet2

Roulette

Jul 19th, 2012
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* C++ Roulette for Trinity Core
  2. Made by Crumpets
  3. Idea and LUA version by Crash45
  4. Error checking and fixed up by Rochet2*/
  5.  
  6.  
  7. class roulette_npc : public CreatureScript
  8. {
  9. public:
  10.     roulette_npc() : CreatureScript("roulette_npc") { }
  11.  
  12.     bool OnGossipHello(Player * pPlayer, Creature * pCreature)
  13.     {
  14.         pPlayer->ADD_GOSSIP_ITEM(3, "I would like to play", GOSSIP_SENDER_MAIN, 1);
  15.         pPlayer->ADD_GOSSIP_ITEM(1, "Nevermind", GOSSIP_SENDER_MAIN, 0);
  16.  
  17.         pPlayer->PlayerTalkClass->SendGossipMenu(141, pCreature->GetGUID()); //This can be any menu you like :)
  18.         return true;
  19.     }
  20.  
  21.     bool OnGossipSelect(Player * pPlayer, Creature * pCreature, uint32 sender, uint32 uiAction)
  22.     {
  23.         pPlayer->PlayerTalkClass->ClearMenus();
  24.         if(uiAction == 1)
  25.         {
  26.             if (pPlayer->isInCombat())
  27.                 pPlayer->GetSession()->SendNotification("You are in Combat!");
  28.             else
  29.             {
  30.                 static std::map<uint32, time_t> PlrCooldowns; // static, so it will stay the same. If it is non static, the type will be auto by default, which means that the map will be destroyed after going out of the "else" statement.
  31.                 if(difftime (time(NULL), PlrCooldowns[pPlayer->GetGUIDLow()]) <= 180) // needs to check if a record for our player exists before using it?
  32.                 {
  33.                     switch (urand(1, 1))
  34.                     {
  35.                     case 1:
  36.                         if (TryToSellItem(pPlayer, pCreature, 36942))
  37.                         {
  38.                             PlrCooldowns[pPlayer->GetGUIDLow()] = time(NULL);
  39.                             pCreature->MonsterSay("This option is on test, But look in your bag!", LANG_UNIVERSAL, NULL);
  40.                         }
  41.                         else
  42.                         {
  43.                             // bags were full, what to do?
  44.                         }
  45.                         break;
  46.                     }
  47.                 }
  48.             }
  49.         }
  50.         pPlayer->CLOSE_GOSSIP_MENU();
  51.         return true;
  52.     }
  53.  
  54. private:
  55.     bool TryToSellItem(Player* pPlayer, Creature* pCreature, uint32 rewardID)
  56.     {
  57.         uint32 noSpaceForCount = 0;
  58.  
  59.         ItemPosCountVec dest;
  60.         uint8 msg = pPlayer->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, rewardID, 1, &noSpaceForCount );
  61.         unsigned int count = 1;
  62.         if (msg != EQUIP_ERR_OK)                                                          
  63.             count -= noSpaceForCount;
  64.  
  65.         if (count == 0 || dest.empty())                                          
  66.         {
  67.             ChatHandler(pPlayer).PSendSysMessage(LANG_ITEM_CANNOT_CREATE, rewardID, noSpaceForCount );
  68.             return false;
  69.         }
  70.  
  71.         Item* item = pPlayer->StoreNewItem( dest, rewardID, true, Item::GenerateItemRandomPropertyId(rewardID));
  72.         return true;
  73.     }
  74. };
  75.  
  76. void AddSC_roulette_npc()
  77. {
  78.     new roulette_npc();
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement