Hello & Welcome to our community. Is this your first visit? Register
Follow us on
Follow us on Facebook Follow us on Twitter Watch us on YouTube


MMOCoin

Likes Likes:  0
Results 1 to 1 of 1
  1. #1
    Graphics Guru

    Join Date
    Feb 2009
    Posts
    1,377
    Post Thanks / Like
    Rep Power
    22
    Reputation
    382

    [Antifarm] PvP Kill, Token Reward Script With Cooldown! Prevent players from kill farming!


    Register to remove this ad
    Made by Sinistah I take no credits except sharing.



    Code:
    // 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.
    
    #include "Chat.h"
    class PvPRewards : PlayerScript
    {
    public:
        PvPRewards() : PlayerScript("PvPRewards") {}
    
    
        // ~ Setting Variables "Not Ideal But it will have to do."  ~
        
        // The item you want to give players.
        uint32 itemID = 45978;
        // Ammount of items to give.
        uint32 ammount = 1;
        // Time in seconds 60 = 1 Minute
        uint32 cooldown = 60;
        // This is the message that is sent when a player does recieve a reward.
        std::string rewardMessage = "|cffff0000[System]|r You recieved a reward and are now on a cooldown.";
        // Thhis is the message that is sent when a player is on cooldown.
        std::string cooldownMessage = "|cffff0000[System]|r You are still on a cooldown and can not recieve a reward.";
    
    
        //IMPORTANT! Unless you know what your doing I do not recommend editing anything below this comment.
    
    
        // This is the map that is going to store all of our player's cooldowns during game play.
        std::unordered_map <uint32, uint32>  cooldownList;
    
    
        // Returns our cooldown from the map if it has one.
        uint32 GetPlayerCD(std::unordered_map<uint32, uint32> m, uint32 key)
        {
            //This gets our player's cooldown from the map and returns it to us in a uint32 form.
            auto itr = m.find(key);
    
    
            if (itr != m.end())
                return itr->second;
    
    
            //This is mainly to make the compiler happy about not all paths returning a value but also serves 
            return NULL;
        }
    
    
        //Updates/Inserts our players unique identifier and their cooldown.
        void UpdatePlayerCD(std::unordered_map<uint32, uint32>& m, uint32 key, uint32 newValue)
        {
            //If it finds a value update it with new value
            auto itr = m.find(key);
            if (itr != m.end()) {
                m[key] = newValue;
            }
            //If that character is not in the map add it.
            else
                m.insert(std::make_pair(key, newValue));
        }
    
    
        //This is where we add our item and send a mssg to our player and then we update the map.
        void AddReward(Player * killer, uint32 itemId, uint32 ammount, uint32 cooldown)
        {
            //Add the item to the player.
            killer->AddItem(itemId, ammount);
            //Send Message.
            ChatHandler(killer->GetSession()).PSendSysMessage(rewardMessage.c_str());
            //Inset Data into map.
            UpdatePlayerCD(cooldownList, killer->GetGUID().GetCounter(), killer->GetTotalPlayedTime() + cooldown);
        }
    
    
        //This is called when a player kills another player.
        void OnPVPKill(Player* killer, Player* /*killed*/)
        {
            //Variable to store the saved cooldown value we get from our map.
            uint32 mapCD;
    
    
            //If the map is empty.
            if (cooldownList.empty())
                mapCD = NULL;
            //Get the cd from the map and stores it in mapCD.
            else
                mapCD = GetPlayerCD(cooldownList, killer->GetGUID().GetCounter());
            
            //If mapCD has no value.
            if (mapCD == NULL)
            {
                AddReward(killer, itemID, ammount, cooldown);
            }
            //If mapCD has a value.
            else
            {
                // If player's played time is higher then the cooldown time.
                if (killer->GetTotalPlayedTime() >= mapCD) {
                    // Add items, Send Message, and Update Map. ~ See Function For More Info ~
                    AddReward(killer, itemID, ammount, cooldown);
                }
                else {
                    // If you are still on cooldown send cooldownMessage.
                    ChatHandler(killer->GetSession()).PSendSysMessage(cooldownMessage.c_str());
                }
            }
        }
    };
    
    
    void AddSC_PvPRewards()
    {
        new PvPRewards();
    }



    › See More: [Antifarm] PvP Kill, Token Reward Script With Cooldown! Prevent players from kill farming!
    Last edited by Wise; 31-07-18 at 02:11 PM.



  2. Related Threads - Scroll Down after related threads if you are only interested to view replies for above post/thread

 

 

Visitors found this page by searching for:

Nobody landed on this page from a search engine, yet!
SEO Blog

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -5. The time now is 08:13 AM.
Powered by vBulletin® Copyright ©2000-2024, Jelsoft Enterprises Ltd.
See More links by ForumSetup.net. Feedback Buttons provided by Advanced Post Thanks / Like (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
vBulletin Licensed to: MMOPro.org