Advertisement
Rochet2

Roulette - Timed

Aug 4th, 2012
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.27 KB | None | 0 0
  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. Modified by Rochet2:
  7. Added timer and changed rewards
  8. */
  9.  
  10. #define WAITTIME 60     // seconds
  11.  
  12. #define REWARD 60000    // item entry
  13. #define AMOUNT 5000     // amount of items
  14.  
  15. class roulette_npc : public CreatureScript
  16. {
  17. public:
  18.     roulette_npc() : CreatureScript("roulette_npc") { }
  19.  
  20.     bool OnGossipHello(Player * player, Creature * creature)
  21.     {
  22.         player->ADD_GOSSIP_ITEM(3, "I wish to play the game of luck!", GOSSIP_SENDER_MAIN, 1);
  23.         player->ADD_GOSSIP_ITEM(1, "Nevermind", GOSSIP_SENDER_MAIN, 0);
  24.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  25.         return true;
  26.     }
  27.  
  28.     bool OnGossipSelect(Player * player, Creature * creature, uint32 sender, uint32 uiAction)
  29.     {
  30.         player->PlayerTalkClass->ClearMenus();
  31.         if (uiAction == 1)
  32.         {
  33.             if(cooldowns.find(player->GetGUIDLow()) != cooldowns.end())
  34.             {
  35.                 double diff = difftime(time(NULL), cooldowns[player->GetGUIDLow()]);
  36.                 if (diff < WAITTIME)
  37.                 {
  38.                     player->GetSession()->SendNotification("You need to wait %ul more seconds", diff);
  39.                     OnGossipHello(player, creature);
  40.                     return true;
  41.                 }
  42.             }
  43.  
  44.             cooldowns[player->GetGUIDLow()] = time(NULL);
  45.  
  46.             switch (urand(1, 4))
  47.             {
  48.             case 1:
  49.                 player->CastSpell(player, 5);
  50.                 creature->MonsterSay("Hahahaha!", LANG_UNIVERSAL, NULL);
  51.                 player->PlayDirectSound(11965);
  52.                 break;
  53.             case 2:
  54.                 creature->MonsterSay("You've won..", LANG_UNIVERSAL, NULL);
  55.                 GiveItemAmount(player, REWARD, AMOUNT);
  56.                 break;
  57.             case 3:
  58.                 player->CastSpell(player, 27604);
  59.                 creature->MonsterYell("YOU ARE NOT PREPARED!", LANG_UNIVERSAL, NULL);
  60.                 player->PlayDirectSound(11466);
  61.                 break;
  62.             case 4:
  63.                 creature->MonsterSay("Lets rock!", LANG_UNIVERSAL, NULL);
  64.                 player->PlayDirectSound(11803);
  65.                 break;
  66.             }
  67.         }
  68.  
  69.         player->CLOSE_GOSSIP_MENU();
  70.         return true;
  71.     }
  72.  
  73. private:
  74.     std::map<uint32, time_t> cooldowns;
  75.  
  76.     bool GiveItemAmount(Player * player, uint32 itemEntry, uint32 amount)
  77.     {
  78.         if (amount < 0)
  79.         {
  80.             player->DestroyItemCount(itemEntry, -amount, true, false);
  81.             return true;
  82.         }
  83.         if (amount == 0)
  84.             amount = 1;
  85.  
  86.         uint32 noSpaceForCount = 0;
  87.  
  88.         ItemPosCountVec dest;
  89.         uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemEntry, amount, &noSpaceForCount);
  90.  
  91.         if (msg != EQUIP_ERR_OK)
  92.             amount -= noSpaceForCount;
  93.  
  94.         if (amount == 0 || dest.empty())
  95.             return false;
  96.  
  97.         Item* item = player->StoreNewItem(dest, itemEntry, true, Item::GenerateItemRandomPropertyId(60000));
  98.         // player->SendNewItem(item, amount, true, false);
  99.         return true;
  100.     }
  101. };
  102.  
  103. void AddSC_roulette_npc()
  104. {
  105.     new roulette_npc();
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement