PvP System

Posting this in case if someone need.

Gonna post few more.

Author: Unknown

Core: Trinity Core

Credits: Trinity Core Team

Format: C++

Site: www.trinitycore.org

[CODE]#include “ScriptPCH.h”

class System_OnPvPKill : public PlayerScript

{

public:

	System_OnPvPKill() : PlayerScript("System_OnPvPKill") {}


struct SystemInfo

{

	uint32 KillStreak;

	uint32 LastGUIDKill;

};

static std::map<uint32, SystemInfo> KillingStreak;

void OnPvPKill(Player *pKiller, Player *pVictim)

{

	uint32 kGUID; 

	uint32 vGUID;

	kGUID = pKiller->GetGUID();

	vGUID = pVictim->GetGUID();	

	if(kGUID == vGUID)

	{

		return;

	}

	if(KillingStreak[kGUID].LastGUIDKill == vGUID)

	{

		return;

	}


	KillingStreak[kGUID].KillStreak++;

	KillingStreak[vGUID].KillStreak = 0;

	KillingStreak[kGUID].LastGUIDKill = vGUID;

	KillingStreak[vGUID].LastGUIDKill = 0;


	switch(KillingStreak[kGUID].KillStreak)

	{

		case 10:

		char msg[500];

		sprintf(msg, "[PvP System]: %s killed %s and is on a 10 kill streak. ", pKiller->GetName(), pVictim->GetName());

		sWorld.SendWorldText(LANG_SYSTEMMESSAGE, msg);

		break;

	}

}

};

void AddSC_System()

{

new System_OnPvPKill;

}[/CODE]

Why I see my code here?

Nevertheless the old version /emoticons/default_tongue.png. Hey Kjanko would you consider re-posting the newest version?

Repost of my version(just modified) With Deathstreak!!:

[CODE]

#include “ScriptPCH.h”

struct SystemInfo

{

uint32 KillStreak;

uint32 LastGUIDKill;

uint32 DeathStreak;

};

static std::map<uint32, SystemInfo> KillingStreak;

class System_OnPVPKill : public PlayerScript

{

    public:

            System_OnPVPKill() : PlayerScript("System_OnPVPKill") {}

void OnPVPKill(Player *killer, Player *killed)

    {

            uint32 kGUID; 

            uint32 vGUID;

            kGUID = killer->GetGUID();

            vGUID = killed->GetGUID();


			if (kGUID == vGUID)		// suicide @.@

                return;


			KillingStreak[vGUID].KillStreak = 0;  // if die always reset

			KillingStreak[vGUID].LastGUIDKill = 0; // if die always reset

			KillingStreak[kGUID].DeathStreak = 0; //if kill deathstreak  = 0


			if (killer->GetGroup())

			{

				if (killer->InBattleground() && !killer->InArena())

					KillingStreak[vGUID].DeathStreak++;  //add 1 deathstreak

			}

			else

				KillingStreak[vGUID].DeathStreak++;


			switch (KillingStreak[vGUID].DeathStreak)

			{

				/*case 3:	

				killed->ResurrectPlayer(1.0f);

				killed->SetPower(POWER_MANA, killed->GetMaxPower(POWER_MANA));

				killed->SpawnCorpseBones();

			    killed->SaveToDB();

				killed->CastSpell(killed,71586,true); //cast shield

				killed->RemoveArenaSpellCooldowns();

				//char msg[500];

                sprintf(msg, "%s is on 3 deathstreak and has been ressed! ",killed->GetName());

                sWorld.SendWorldText(LANG_SYSTEMMESSAGE, msg);

				break;*/


				case 4:

				killed->ResurrectPlayer(1.0f);

				killed->SetPower(POWER_MANA, killed->GetMaxPower(POWER_MANA));

				killed->SpawnCorpseBones();

			    killed->SaveToDB();

				killed->CastSpell(killed,21074,true); //visual ress

				killed->CastSpell(killed,24378,true);  //cast buff

				killed->CastSpell(killed,71586,true); //cast shield

				killed->RemoveArenaSpellCooldowns();

				char msg[500];

                sprintf(msg, "%s is on 4 deathstreak and has been ressed! ",killed->GetName());

                sWorld.SendZoneText(killer->GetZoneId(), msg);

				KillingStreak[vGUID].DeathStreak++; // sometimes it dont count 

				break;


			}


            if (!(KillingStreak[kGUID].LastGUIDKill == vGUID)) // dont let grind

			{

				if (!killer->GetGroup() || (killer->InBattleground() && !killer->InArena())) // dont count killstreak if grouped and not in BG or arena

				{

					KillingStreak[kGUID].KillStreak++;      // add 1 killstreak

					KillingStreak[kGUID].LastGUIDKill = vGUID; // remember last killed

						if (killer->GetAreaId() == 3217)

							killer->AddItem(54637, 1);

				}

				else 

					return;

			}

			else

				return;


            switch(KillingStreak[kGUID].KillStreak)

            {


					case 2:

					{

						int x = urand(0,10);

						int RandomSpell[] = { 

							70788, 62398, 60342, 69861, 65712, 70571, 11010, 72523, 44800, 72100, 71994 };

						killer->CastSpell(killer,RandomSpell[x],true);

					}

					break;


					case 4:

					killer->CastSpell(killer,65828,true);

					break;


					case 5:

					char msg[500];

					sprintf(msg, "[PvP System]: %s killed %s and is on a 5 kill streak. ", killer->GetName(), killed->GetName());

                    sWorld.SendZoneText(killer->GetZoneId(), msg);

					break;


					case 6:

					killer->CastSpell(killer,71586,true);

					break;


					case 8:

					killer->CastSpell(killer,24378,true);

					break;


                    case 10:

                    sprintf(msg, "[PvP System]: %s killed %s and is on a 10 kill streak. ", killer->GetName(), killed->GetName());

                    sWorld.SendZoneText(killer->GetZoneId(), msg);

                    killer->AddItem(45706, 2);

                    break;


					case 20:

                    sprintf(msg, "[PvP System]: %s killed %s and is on a 20 kill streak. ", killer->GetName(), killed->GetName());

                    sWorld.SendZoneText(killer->GetZoneId(), msg);

                    killer->AddItem(45706, 5);

                    break;


                    case 30:

                    sprintf(msg, "[PvP System]: %s killed %s and is on a 30 kill streak. ", killer->GetName(), killed->GetName());

                    sWorld.SendZoneText(killer->GetZoneId(), msg);

                    killer->AddItem(45706, 8);

                    break;


                    case 40:

                    sprintf(msg, "[PvP System]: %s killed %s and is on a 40 kill streak. ", killer->GetName(), killed->GetName());

                    sWorld.SendZoneText(killer->GetZoneId(), msg);

					killer->AddItem(45706, 12);

                    KillingStreak[kGUID].KillStreak = 0;

                    break;

            }

    }

};

void AddSC_System_OnPVPKill()

{

new System_OnPVPKill;

}

[/code][/CODE]

Btw , this is zone announce not server announce /emoticons/default_smile.png(for big servers /emoticons/default_tongue.png)

I’ve tried to install it but it don’t work…

http://www.trinitycore.org/f/index.php?showtopic=16&pid=256

this code works for me /emoticons/default_smile.png and i think its easy to understand /emoticons/default_tongue.png

[CODE]

#include “ScriptPCH.h”

///////////////////////////////////////////////////////////////////////

/////////////////////// CONFIG /////////////////////////////

/////////////////////////////////////////////////////////////////////

float Version = 2.50f; //Don’t touch this.

bool PvPSystemEnabled = true; //Set to false if you want to disable the PvP System

bool OnlyInBattlegrounds = false; //Set to true if you want to enable this only in battlegrounds.

bool LooseTokenOnPvPDeath = false; //Set to true if you want the victim to loose tokens when the victim dies.

int32 AmountOfItemsYouWantTheVictimToLoose = 1; //Amount of items you want the victim to loose when victim dies.

bool AddTokenOnPvPKill = true; //Set to false if you don’t want the killer to be rewarded.

int32 ItemReward = 40753; //The ItemID of the reward.

int32 AmountOfRewardsOnKillStreak[5] = { 1, 3, 5, 7, 10 }; //With how many items you want to reward the killer when he slays the victim.

int32 HowManyTimesYouWantTheKillerToGetAwardedForKillingTheSameVictim = 1; //Name speaks for It self.

const int32 KillerStreak1 = 10;

const int32 KillerStreak2 = 20;

const int32 KillerStreak3 = 30;

const int32 KillerStreak4 = 40;

const int32 KillerStreak5 = 50;

int32 KillStreaks[5] = { KillerStreak1, KillerStreak2, KillerStreak3, KillerStreak4, KillerStreak5 };//On how many kills the killstreaks should announce & Reward.

int32 PVP_System_SamePlayer = 1;

///////////////////////////////////////////////////////////////////

/////////////////////// END ////////////////////////////

/////////////////////////////////////////////////////////////////

struct SystemInfo

{

uint32 		KillStreak;

uint32 		LastGUIDKill;

uint8 		KillCount;

};

static std::map<uint32, SystemInfo> KillingStreak;

class System_OnPvPKill : public PlayerScript

{

public:

    System_OnPvPKill() : PlayerScript("System_OnPvPKill") {}

void OnPVPKill(Player *pKiller, Player *pVictim)

{

if(PvPSystemEnabled == false)

{

         return;

}

else if(PvPSystemEnabled == true)

{

    uint32 kGUID; 

    uint32 vGUID;

    char msg[500];

    kGUID = pKiller->GetGUID();

    vGUID = pVictim->GetGUID();                 

    if(kGUID == vGUID)

    {

      return;

    }


  if(KillingStreak[kGUID].LastGUIDKill == vGUID)

	if (PVP_System_SamePlayer !=1 )

	{

		return;

	}

	else

    {

    KillingStreak[kGUID].KillCount++;

    KillingStreak[vGUID].KillCount = 1;

      pKiller->AddItem(ItemReward, 1);

    if(LooseTokenOnPvPDeath == true)

      pVictim->DestroyItemCount(ItemReward, AmountOfItemsYouWantTheVictimToLoose, true, false);

    }


  if(KillingStreak[kGUID].LastGUIDKill != vGUID)

  {

    KillingStreak[kGUID].KillCount = 1;

    KillingStreak[vGUID].KillCount = 1;

  }


  if(KillingStreak[kGUID].KillCount == HowManyTimesYouWantTheKillerToGetAwardedForKillingTheSameVictim)

  {

    return;

  }


  if(OnlyInBattlegrounds == true)

    {

    if(!pKiller->GetMap()->IsBattleground())

       return;

  }


    KillingStreak[kGUID].KillStreak++;

    KillingStreak[vGUID].KillStreak = 0;

    KillingStreak[kGUID].LastGUIDKill = vGUID;

    KillingStreak[vGUID].LastGUIDKill = 0;

  if(AddTokenOnPvPKill == true)

      pKiller->AddItem(ItemReward, 1);

  if(LooseTokenOnPvPDeath == true)

    pVictim->DestroyItemCount(ItemReward, AmountOfItemsYouWantTheVictimToLoose, true, false);


    switch(KillingStreak[kGUID].KillStreak)

    {

    case KillerStreak1:

    sprintf(msg, "[PvP System]: %s killed %s and is on a %u kill streak. ", pKiller->GetName(), pVictim->GetName(), KillStreaks[1]);

    sWorld.SendWorldText(LANG_SYSTEMMESSAGE, msg);

    pKiller->AddItem(ItemReward, AmountOfRewardsOnKillStreak[1]);

    break;


    case KillerStreak2:

    sprintf(msg, "[PvP System]: %s killed %s and is on a %u kill streak. ", pKiller->GetName(), pVictim->GetName(), KillStreaks[2]);

    sWorld.SendWorldText(LANG_SYSTEMMESSAGE, msg);

    pKiller->AddItem(ItemReward, AmountOfRewardsOnKillStreak[2]);

    break;


    case KillerStreak3:

    sprintf(msg, "[PvP System]: %s killed %s and is on a %u kill streak. ", pKiller->GetName(), pVictim->GetName(), KillStreaks[3]);

    sWorld.SendWorldText(LANG_SYSTEMMESSAGE, msg);

    pKiller->AddItem(ItemReward, AmountOfRewardsOnKillStreak[3]);

    break;


    case KillerStreak4:

    sprintf(msg, "[PvP System]: %s killed %s and is on a %u kill streak. ", pKiller->GetName(), pVictim->GetName(), KillStreaks[4]);

    sWorld.SendWorldText(LANG_SYSTEMMESSAGE, msg);

    pKiller->AddItem(ItemReward, AmountOfRewardsOnKillStreak[4]);

    break;


    case KillerStreak5:

    sprintf(msg, "[PvP System]: %s killed %s and is on a %u kill streak. ", pKiller->GetName(), pVictim->GetName(), KillStreaks[5]);

    sWorld.SendWorldText(LANG_SYSTEMMESSAGE, msg);

    pKiller->AddItem(ItemReward, AmountOfRewardsOnKillStreak[5]);

    KillingStreak[kGUID].KillStreak = 0;

    break;

 }

}

}

};

void AddSC_PVP_System()

{

new System_OnPvPKill;

}[/CODE]

Okey, but how can I install this script. All looks ok, i’ve modified the script loader and added the script to the CMakeList… But it don’t work…

I like this script. Only thing missing is it might encourage level 80’s to run around starting areas and kill level 1’s. I did not see and restrictions on player levels. Maybe putting a 5-10 level restriction… or is this handled by the core somehow?

Kjanko, with your permission, I would like to test this, create a patch and add it to my patch repo.

I will give credit where credit is due, and I will not add it if you say no.

That is easy to add:

if ((pKiller->getLevel() - pVictim->getLevel()) < 5) return; 

This will stop the function if the difference is above 4 levels

error C2228: left of ‘.SendWorldText’ must have class/struct/union

2> type is ‘World *’

2> did you intend to use ‘->’ instead?

anyone know about that?

Hmm ye around 10800 there were some changes with this,replace sWorld.SendWorldText with sWorld->SendWorldText

They made alot of changes from . to → including but not limited to:

sObjectMgr. is now sObjectMgr->

sLog. is now sLog->

and many other s*. are now s*->

took me awhile to figure that out. all of a sudden all my patches got hundreds of ACE errors. that is the cause.

sure wish there was an edit button. anyways, that will work if the attacker is higher level, but what about if a level 1 decides to attack a level 80. the level 80 should not get credit.

I can modify a script and fix errors. I use logic and common sense and alot of research, but I couldn’t write a script from scratch if my life depended on it. hell I can’t even write a standalone script to print “Hello World”…

and yes, I took a C++ class, and passed with an A…

I think it is kinda impossible that lvl 1 kills lvl 80(if you mean that)

The function only used when somebody is killed, who is killed and by who is he killed, not who first attacked. But if you also want that to have secured you can do this too:

[CODE]if ((pKiller->getLevel() - pVictim->getLevel()) < 5 || (pVictim->getLevel() - pKiller->getLevel()) < -5)

return; [/CODE]

The best way to learn C++ , is start to modify small codes, like add some function in Player::Update() , im also not that good with but you dont need to be good if you are just a dev for fixing small shit

http://www.trinitycore.org/f/index.php?/topic/70-release-different-pvp-systems/ - Original topic

Ask for help there.

I prefer this

[CODE]#include “ScriptPCH.h”

class System_OnPvPKill : public PlayerScript

{

    public:

            System_OnPvPKill() : PlayerScript("System_OnPvPKill") {}


    struct SystemInfo

    {

            uint32 KillStreak;

            uint32 LastGUIDKill;


    };

static std::map<uint32, SystemInfo> KillingStreak;

void OnPvPKill(Player *pKiller, Player *pVictim)

    {

			uint32 killer; 

            uint32 killed;

            killer = pKiller->GetGUID();

            killed = pVictim->GetGUID();     

            if(killer == killed) return;

			if ((pKiller->getLevel() - pVictim->getLevel()) < 5) return;



            KillingStreak[killer].KillStreak++;

            KillingStreak[killed].KillStreak = 0;

            KillingStreak[killer].LastGUIDKill = killed;

            KillingStreak[killed].LastGUIDKill = 0;


            switch(KillingStreak[killer].KillStreak)

            {

                    char msg[500];


                    case 5:

                    sprintf(msg, "[PvP System]: %s killed %s and is on a 5 kill streak. (Bonus +1500 honor + 10 arena ", pKiller->GetName(), pVictim->GetName());

                    sWorld->SendWorldText(LANG_SYSTEMMESSAGE, msg);

					pKiller->ModifyHonorPoints(1500);

					pVictim->ModifyArenaPoints(10);


                    break;


                    case 10:

                    sprintf(msg, "[PvP System]: %s killed %s and is on a 10 kill streak. (Bonus + 2500 honor + 20 arena ", pKiller->GetName(), pVictim->GetName());

                    sWorld->SendWorldText(LANG_SYSTEMMESSAGE, msg);

					pKiller->ModifyHonorPoints(2500);

					pVictim->ModifyArenaPoints(20);

                    break;


                    case 15:

                    sprintf(msg, "[PvP System]: %s killed %s and is on a 15 kill streak. (Bonus + 5000 honor + 30 arena ", pKiller->GetName(), pVictim->GetName());

                    sWorld->SendWorldText(LANG_SYSTEMMESSAGE, msg);

					pKiller->ModifyHonorPoints(5000);

					pVictim->ModifyArenaPoints(30);

                    break;


                    case 20:

                    sprintf(msg, "[PvP System]: %s killed %s and is on a 20 kill streak. (Bonus + 10000 honor + 50 arena ", pKiller->GetName(), pVictim->GetName());

                    sWorld->SendWorldText(LANG_SYSTEMMESSAGE, msg);

					pKiller->ModifyHonorPoints(10000);

					pVictim->ModifyArenaPoints(50);

                    break;


                    case 25:

                    sprintf(msg, "[PvP System]: %s killed %s and is on a EPIC 25 kill streak. (Bonus + 25000 honor + 100 arena ", pKiller->GetName(), pVictim->GetName());

                    sWorld->SendWorldText(LANG_SYSTEMMESSAGE, msg);

					pKiller->ModifyHonorPoints(25000);

					pVictim->ModifyArenaPoints(100);

						break;


            }

    }

};

void AddSC_PVP_System()

{

new System_OnPvPKill;

}[/CODE]

sprintf(msg, "[PvP System]: %s killed %s and is on a EPIC 25 kill streak. (Bonus + 25000 honor + [b]1000 assrena[/b] ", pKiller->GetName(), pVictim->GetName());

1000 assrena

wat.

Besides that typo, it looks good. /emoticons/default_smile.png

lol nice typo xD

i couldn’t figure out how to load this custom script. Any help in the ScriptLoader.cpp area?

add

[CODE]void AddSC_PVP_System();

AddSC_PVP_System();

[/CODE]

into the src/server/game/scripting/scriptloader.cpp (look at how other lines are put into there)

(here is an example:

at top of scriptloader.cpp

[CODE]#include “ScriptLoader.h”

//examples

void AddSC_example_creature();

void AddSC_example_escort();

void AddSC_example_gossip_codebox();

void AddSC_example_misc();

void AddSC_example_commandscript();

//custom

void AddSC_PVP_System();[/CODE]

at the bottom of the scriptloader.cpp

[CODE]void AddCustomScripts()

{

#ifdef SCRIPTS

/* This is where custom scripts should be added. */


//custom

AddSC_PVP_System();[/CODE]

)

simple?

and change the txt afther AddSC_ to the script you want to use here.

like

void AddSC_System_OnPVPKill

and

AddSC_System_OnPVPKill

don’t forget to add the script into cmake too.