kusanagy

PvPRewards

Sep 22nd, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.37 KB | None | 0 0
  1. // Made by Sinistah @Ac-Web / Taco @ Lordcraft / TheEpicLazyTaco @BitBucket :) It would be nice if you did not remove this when you repost this years from now.
  2.  
  3. class PvPRewards : PlayerScript
  4. {
  5. public:
  6.     PvPRewards() : PlayerScript("PvPRewards") {}
  7.  
  8.     // ~ Setting Variables "Not Ideal But it will have to do."  ~
  9.    
  10.     // The item you want to give players.
  11.     uint32 itemID = 45978;
  12.     // Ammount of items to give.
  13.     uint32 ammount = 1;
  14.     // Time in seconds 60 = 1 Minute
  15.     uint32 cooldown = 60;
  16.     // This is the message that is sent when a player does recieve a reward.
  17.     std::string rewardMessage = "|cffff0000[System]|r You recieved a reward and are now on a cooldown.";
  18.     // Thhis is the message that is sent when a player is on cooldown.
  19.     std::string cooldownMessage = "|cffff0000[System]|r You are still on a cooldown and can not recieve a reward.";
  20.  
  21.     //IMPORTANT! Unless you know what your doing I do not recommend editing anything below this comment.
  22.  
  23.     // This is the map that is going to store all of our player's cooldowns during game play.
  24.     std::unordered_map <uint32, uint32>  cooldownList;
  25.  
  26.     // Returns our cooldown from the map if it has one.
  27.     uint32 GetPlayerCD(std::unordered_map<uint32, uint32> m, uint32 key)
  28.     {
  29.         //This gets our player's cooldown from the map and returns it to us in a uint32 form.
  30.         auto itr = m.find(key);
  31.  
  32.         if (itr != m.end())
  33.             return itr->second;
  34.  
  35.         //This is mainly to make the compiler happy about not all paths returning a value but also serves
  36.         return NULL;
  37.     }
  38.  
  39.     //Updates/Inserts our players unique identifier and their cooldown.
  40.     void UpdatePlayerCD(std::unordered_map<uint32, uint32>& m, uint32 key, uint32 newValue)
  41.     {
  42.         //If it finds a value update it with new value
  43.         auto itr = m.find(key);
  44.         if (itr != m.end()) {
  45.             m[key] = newValue;
  46.         }
  47.         //If that character is not in the map add it.
  48.         else
  49.             m.insert(std::make_pair(key, newValue));
  50.     }
  51.  
  52.     //This is where we add our item and send a mssg to our player and then we update the map.
  53.     void AddReward(Player * killer, uint32 itemId, uint32 ammount, uint32 cooldown)
  54.     {
  55.         //Add the item to the player.
  56.         killer->AddItem(itemId, ammount);
  57.         //Send Message.
  58.         ChatHandler(killer->GetSession()).PSendSysMessage(rewardMessage.c_str());
  59.         //Inset Data into map.
  60.         UpdatePlayerCD(cooldownList, killer->GetGUID().GetCounter(), killer->GetTotalPlayedTime() + cooldown);
  61.     }
  62.  
  63.     //This is called when a player kills another player.
  64.     void OnPVPKill(Player* killer, Player* /*killed*/)
  65.     {
  66.         //Variable to store the saved cooldown value we get from our map.
  67.         uint32 mapCD;
  68.  
  69.         //If the map is empty.
  70.         if (cooldownList.empty())
  71.             mapCD = NULL;
  72.         //Get the cd from the map and stores it in mapCD.
  73.         else
  74.             mapCD = GetPlayerCD(cooldownList, killer->GetGUID().GetCounter());
  75.        
  76.         //If mapCD has no value.
  77.         if (mapCD == NULL)
  78.         {
  79.             AddReward(killer, itemID, ammount, cooldown);
  80.         }
  81.         //If mapCD has a value.
  82.         else
  83.         {
  84.             // If player's played time is higher then the cooldown time.
  85.             if (killer->GetTotalPlayedTime() >= mapCD) {
  86.                 // Add items, Send Message, and Update Map. ~ See Function For More Info ~
  87.                 AddReward(killer, itemID, ammount, cooldown);
  88.             }
  89.             else {
  90.                 // If you are still on cooldown send cooldownMessage.
  91.                 ChatHandler(killer->GetSession()).PSendSysMessage(cooldownMessage.c_str());
  92.             }
  93.         }
  94.     }
  95. };
  96.  
  97. void AddSC_PvPRewards()
  98. {
  99.     new PvPRewards();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment