Jump to content

My ONKILL PvP Script


Guest chmuun
 Share

Recommended Posts

These 2 files are a class file for a PvP script of mine, it saves/loads/stores the PvP Stats(onpvpkill) made on arcemu, can some 1 please convert this to work with MaNGOS, i've tried really hard but idk about the vector and objmgr.getplayer or things like that

PvPManager.cpp:

#include "StdAfx.h"
#include "PvPManager.h"

PvPMgr::PvPMgr()
{
   Index            = 0;
   CurrentKills    = 0;
   TotalKills        = 0;
   GroupKills        = 0;
   TotalDeaths        = 0;
   LastGuid        = 0;
   LastGuidCount    = 0;
   Spree            = 0;
   LastSpree        = 0;
   CurrentDeaths    = 0;
   IsInTurny        = false;
}

void PvPMgr::SaveData()
{
   CharacterDatabase.Query("REPLACE INTO `pvpmanager` VALUES
('%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u')", Index, CurrentKills, TotalKills, GroupKills, Spree, TotalDeaths, CurrentDeaths, LastGuid, LastGuidCount);
}
void PvPMgr::LoadData()
{
   QueryResult * result = CharacterDatabase.Query("SELECT * FROM `pvpmanager` WHERE `index` = '%u'", Index);
   if(!result)
   {
       return;
   }
   Field * rows = result->Fetch();
   CurrentKills    = rows[1].GetUInt32();
   TotalKills        = rows[2].GetUInt32();
   GroupKills        = rows[3].GetUInt32();
   Spree            = rows[4].GetUInt32();
   LastSpree        = rows[4].GetUInt32();
   TotalDeaths        = rows[5].GetUInt32();
   CurrentDeaths    = rows[6].GetUInt32();
   LastGuid        = rows[7].GetUInt32();
   LastGuidCount    = rows[8].GetUInt32();
}

void PvPMgr::AddItem(const uint32 &ItemID, const uint32 &Amt, const bool &Stack)
{
   Item * ItemToAdd;
   SlotResult Slot;
   Player * Plr = objmgr.GetPlayer(Index);

   if(Plr == NULL)
       return;
   if(Stack)
   {
       ItemToAdd = Plr->GetItemInterface()->FindItemLessMax(ItemID, Amt, false);
       if(ItemToAdd != NULL)
       {
           ItemToAdd->ModUnsigned32Value(ITEM_FIELD_STACK_COUNT, Amt);
           ItemToAdd->m_isDirty = true;
           Plr->BroadcastMessage("%s%s x%u Awarded", MSG_COLOR_GOLD, ItemToAdd->GetProto()->Name1, Amt);
           return;
       }

   }
   for(uint32 i = 1;i <= Amt;i++)
   {
       ItemToAdd = objmgr.CreateItem(ItemID, Plr);

       if(ItemToAdd == NULL)
           return; // failed creation, no memory to allocate, or invalid item id

       Slot = Plr->GetItemInterface()->FindFreeInventorySlot(ItemToAdd->GetProto());

       if(Slot.Result)
       {
           Plr->GetItemInterface()->SafeAddItem(ItemID, Slot.ContainerSlot, Slot.Slot);
           Plr->BroadcastMessage("%s%s x1 Awarded", MSG_COLOR_GOLD, ItemToAdd->GetProto()->Name1);
       }
       else
           Plr->BroadcastMessage("No free inventory slots could be located, aborting");
   }

}

PvPStorage *PvPStorage::Instance = NULL;

PvPStorage::PvPStorage()
{

}

PvPStorage *PvPStorage::GetInstance()
{
   if(Instance == NULL)
       Instance = new PvPStorage();
   return Instance;
}

PvPMgr *PvPStorage::CreateMgr(const uint32 &Index)
{
   PvPMgr *Mgr = new PvPMgr();

   if(Mgr == NULL)
       return NULL; // no memory to allocate

   Mgr->Index = Index;

   StorageLock.Acquire();
       Vect.push_back(Mgr);
   StorageLock.Release();
   return Mgr;
}

PvPMgr *PvPStorage::GetMgr(const uint32 &Index, const bool Create)
{
   StorageLock.Acquire();
   for(Itr = Vect.begin();Itr != Vect.end();Itr++)
   {
       if((*Itr)->Index == Index)
       {
           StorageLock.Release();
           return (*Itr);
       }

   }
   StorageLock.Release();

   if(Create)
   {
       PvPMgr * mgr = CreateMgr(Index);
       mgr->LoadData();
       return mgr;
   }
   return NULL;
}

void PvPStorage::CleanVect()
{
   if(Vect.empty())
       return;

   StorageLock.Acquire();
   Itr = Vect.begin();
   while(Itr != Vect.end())
   {
       Player * Eraser = objmgr.GetPlayer((*Itr)->Index);
       if(Eraser == NULL || Eraser->IsInWorld() == false || Eraser->GetSession() == NULL)
       {
           if((*Itr)->Summon)
           {
               (*Itr)->Summon->Despawn(0,0);
           }
           Itr = Vect.erase(Itr);
       }
       else
       {
           Itr++;
       }
   }

   StorageLock.Release();

}

PvPManager.h:

#ifndef PvPMgr_H
#define PvPMgr_H

#include "StdAfx.h"
#include "Setup.h"

class PvPMgr
{
   private:
       bool IsInTurny;

   public:
       uint32 Index;
       uint32 CurrentKills;
       uint32 TotalKills;
       uint32 GroupKills;
       uint32 TotalDeaths;
       uint32 LastGuid;
       uint32 LastGuidCount;
       uint32 Spree;
       uint32 LastSpree;
       uint32 CurrentDeaths;

       Creature * Summon;
       PvPMgr();
       void AddItem(const uint32 &ItemID, const uint32 &Amt, const bool &Stack = false);
       void SaveData();
       void LoadData();

};

class PvPStorage : public EventableObject
{
   private:
       static PvPStorage *Instance;
       vector<PvPMgr*> Vect;
       vector<PvPMgr*>::iterator Itr;
       Mutex StorageLock;

       PvPStorage();
       void CleanVect();

   public:
       static PvPStorage *GetInstance();
       PvPMgr *CreateMgr(const uint32 &Index);
       PvPMgr *GetMgr(const uint32 &Index, const bool Create);
       void StartTimer();
       vector<PvPMgr*> GetVect() 
       {
           return Vect;
       }
};

#endif

SQL CODE:

CREATE TABLE `pvpmanager` (

`index` int(20) unsigned NOT NULL AUTO_INCREMENT,

`currentkills` int(5) unsigned DEFAULT NULL,

`totalkills` int(20) unsigned DEFAULT NULL,

`groupkills` int(20) unsigned DEFAULT NULL,

`spree` int(5) unsigned DEFAULT NULL,

`totaldeaths` int(20) unsigned DEFAULT NULL,

`currentdeaths` int(5) unsigned DEFAULT NULL,

`lastguid` int(20) unsigned DEFAULT NULL,

`lastguidcount` int(5) unsigned DEFAULT NULL,

PRIMARY KEY (`index`)

) ENGINE=InnoDB AUTO_INCREMENT=47760 DEFAULT CHARSET=latin1

Link to comment
Share on other sites

When I converted my Ascent scripts to Mangos, I wrote some things to support hooks. For the Ascent PvP script like that you need to add functions in worldsession, unit and characterhandler to trigger your custom script in SD2

void WorldSession::HandlePVPKillPlayer(Player *killed)
{
   Script->PVPKillPlayer(GetPlayer(), killed);
}

For one of the examples..

Link to comment
Share on other sites

Stab can u tell me where to put the custom hooks?

you would want to create a new file in SD2 like hooks.cpp or whatever

void PVPKillPlaye(Player *killer, Player *killed)

{

}

void AddSC_hooks()

{

Script *newscript;

newscript = new Script;

newscript->Name = "scripted_hooks";

newscript->pPVPKillPlayer = &PVPKillPlayer;

newscript->RegisterSelf();

}

Link to comment
Share on other sites

  • 3 weeks later...

I am having problems with my script on compile

I want to know how to convery UNIT to PLAYER or how to make a new instance of PLAYER by Guid or how to get WorldSession of UNIT

PLEASE HELP ME!

this = Player*

pVictim = Unit*

Player * KillerP = this;

Player * VictimP = Player(pVictim);

ChatHandler * KillerC = ChatHandler(this);

ChatHandler * VictimC = ChatHandler(pVictim);

Thanks in advance

Link to comment
Share on other sites

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use