PDA

View Full Version : [SOLVED] Last script c++



Minodevs
07-15-2016, 09:10 AM
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
07-15-2016, 05:44 PM
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.




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
07-16-2016, 08:00 AM
Thanks i well test it anway

Minodevs
07-16-2016, 12:06 PM
its works thanks for That script but how i can coloring it names that i nided :) can you edit it for meh

Minodevs
07-16-2016, 12:24 PM
That i want to Add a Spell when killed a Player receving like Soul of respawn, can you edit it for meh i mean that spell, http://www.wowhead.com/spell=20707/soulstone and we Edit that, Colors of Kiling Streak names just if your editing it for meh ili happy really :)

Tommy
07-16-2016, 04:43 PM
Read the comments on the script! You can add spells on certain killstreaks by doing "player->CastSpell" inside of a case:



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

// You can also add more cases below to do more stuff during a killstreak
}


You can add colors by doing:



|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:



ChatHandler(killer->GetSession()).PSendSysMessage("You killed |cffcc3333 (http://www.color-hex.com/color/cc3333)%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.

Minodevs
07-16-2016, 06:44 PM
Thanks toomy my favorite boy :)