• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Last script c++

Status
Not open for further replies.

Minodevs

Emulation Addict
hello boys i"am looking a kill streak c++ script its are last one as i nided for Lastest Verison 60 DBT if anyone Glad to help me can share me that script :)
 

Tommy

Founder
I don't normally do this, but a Killstreak system is pretty simple. I did this in Visual Studio and didn't receive any errors; however, I did not test it. Everything should be self-explanatory but regardless I commented some stuff.

Basic killstreak
  • Farm prevention
  • Can do stuff on specific kills. e.g. At 5 kills you could add an aura to give the player a greater advantage.

Code:
struct KillStreak
{
    uint32 kills;
    uint32 lastKilledGuid; // Prevent gaining kills from previously killed player
};

std::unordered_map<uint32, KillStreak> KillStreakContainer;
std::mutex killstreak_mutex;

class player_killstreak : public PlayerScript
{
public:
    player_killstreak() : PlayerScript("player_killstreak") { }

    void OnPVPKill(Player* killer, Player* killed) override
    {
        uint32 killerGuid = killer->GetGUID().GetCounter();
        uint32 killedGuid = killed->GetGUID().GetCounter();
        const char* killedName = killed->GetName().c_str();
        bool wasMyLastVictim = false;
        uint32 killedKills = 0;

        {
            std::lock_guard<std::mutex> guard(killstreak_mutex);
            wasMyLastVictim = (KillStreakContainer[killerGuid].lastKilledGuid == killedGuid);
            killedKills = KillStreakContainer[killedGuid].kills;

            KillStreakContainer[killerGuid].lastKilledGuid = killedGuid; // Log our previous kill (prevent farming)
            KillStreakContainer[killedGuid].kills = 0; // Reset victim kills
            KillStreakContainer[killedGuid].lastKilledGuid = 0; // Reset victim's last victim

            if (!wasMyLastVictim)
            {
                KillStreakContainer[killerGuid].kills++; // Increment kills

                // Do stuff on streaks below
                switch (KillStreakContainer[killerGuid].kills)
                {
                    case 5: // 5 kills
                        break;
                    case 10: // 10 kills
                        break;
                }
            }
        }

        if (wasMyLastVictim)
        {
            ChatHandler(killer->GetSession()).PSendSysMessage("You killed %s already. Kill another player to earn something from him/her again.", killedName);
            ChatHandler(killed->GetSession()).SendSysMessage("The person who killed you did not benefit from your death. They killed you before. Now laugh at them!");
            return;
        }

        std::ostringstream ss;
        ss << killer->GetName()
            << " has ruined " << killedName << "'s"
            << " KillStreak of " << killedKills;

        sWorld->SendGlobalText(ss.str().c_str(), NULL);
    }
};

void SetupKillStreak()
{
    new player_killstreak;
}

Updated the script. Thanks for Rochet2 for pointing out the thread issue and showing the ways of the mutex.
 

Minodevs

Emulation Addict
its works thanks for That script but how i can coloring it names that i nided :) can you edit it for meh
 

Tommy

Founder
Read the comments on the script! You can add spells on certain killstreaks by doing "player->CastSpell" inside of a case:

Code:
                // Do stuff on streaks below
                switch (KillStreakContainer[killerGuid].kills)
                {
                    case 5: // 5 kills
                        [COLOR="#00FF00"]player->CastSpell(player, spellid, false);[/COLOR]
                        break;
                    case 10: // 10 kills
                        break;

                    [COLOR="#00FF00"]// You can also add more cases below to do more stuff during a killstreak[/COLOR]
                }

You can add colors by doing:

Code:
|cffCOLORHEX My Player's Name|r

"|cff" : Starts the color
"|r" : Ends the color

And replace COLORHEX with a color hex code: http://www.color-hex.com/ (without the #)

For example:

Code:
ChatHandler(killer->GetSession()).PSendSysMessage("You killed |cff[URL="http://www.color-hex.com/color/cc3333"]cc3333[/URL]%s|r already. Kill another player to earn something from him/her again.", killedName);

Now "%s" being the player's name, the player's name will have a color now.
 
Status
Not open for further replies.
Top