Alvanaar
04-23-2009, 03:52 AM
Hey AC-Web, I haven't released anything lately, so I decided to release this C++ script.
Basically, this script gives you an item every time you kill a player in a certain area. It's a C++ script so you have to compile it!
Here it is...
#include "StdAfx.h"
#include "Setup.h"
// Item Kill System
//
// Alvanaar
void AddItem(Player* Plr, const uint32 &ItemID, const uint32 &Amt, const bool &Stack)
{
Item *ItemToBeAdded;
SlotResult Slot;
if(Plr == NULL)
return;
if(Stack)
{
ItemToBeAdded = Plr->GetItemInterface()->FindItemLessMax(ItemID, Amt, false);
if(ItemToBeAdded != NULL)
{
ItemToBeAdded->ModUnsigned32Value(ITEM_FIELD_STACK_COUNT, Amt);
ItemToBeAdded->m_isDirty = true;
Plr->BroadcastMessage("%s%s x%u awarded for your kill!", MSG_COLOR_GOLD, ItemToBeAdded->GetProto()->Name1, Amt);
return;
}
}
for(uint32 i = 1;i <= Amt;i++)
{
ItemToBeAdded = objmgr.CreateItem(ItemID, Plr);
if(ItemToBeAdded == NULL)
return; // :O it didn't work!
Slot = Plr->GetItemInterface()->FindFreeInventorySlot(ItemToBeAdded->GetProto());
if(Slot.Result)
{
Plr->GetItemInterface()->SafeAddItem(ItemID, Slot.ContainerSlot, Slot.Slot);
Plr->BroadcastMessage("%s%s x1 awarded for you kill!", MSG_COLOR_GOLD, ItemToBeAdded->GetProto()->Name1);
}
else
Plr->SendAreaTriggerMessage("You have no free inventory slots, aborting.");
}
}
void OnKill(Player* pPlayer, Player* pVictim)
{
if(pPlayer->GetMapId() != 560 || pVictim->GetMapId() != 560)
return; // Both players must be at map 560 for the killer to receive the item
if(pVictim->getLevel() < pPlayer->getLevel())
return; // Killer receives item only from killing a player their level and above
if(pPlayer->GetLowGUID() == pVictim->GetLowGUID())
return; // If player suicides, no award is given
if(pPlayer->GetTeam() == pVictim->GetTeam())
return; // Award only from killing the other faction
AddItem(pPlayer, 29434, 1, true);
// "29434" is the item ID (change it if you want)
// "1" is the amount of the item to give (change it if you want)
// and the "true" means that we stack the item
// Change "true" to "false" if you want the item to not stack when it enters your inventory
return;
}
void SetupItemRewardScript(ScriptMgr* mgr)
{
mgr->register_hook(SERVER_HOOK_EVENT_ON_KILL_PLAYER, (void*)OnKill);
}
Read through the script. I have put the comments in green text to make it easier to edit and understand :)
Hope this is useful to some people.
Cheers,
Alvanaar
Basically, this script gives you an item every time you kill a player in a certain area. It's a C++ script so you have to compile it!
Here it is...
#include "StdAfx.h"
#include "Setup.h"
// Item Kill System
//
// Alvanaar
void AddItem(Player* Plr, const uint32 &ItemID, const uint32 &Amt, const bool &Stack)
{
Item *ItemToBeAdded;
SlotResult Slot;
if(Plr == NULL)
return;
if(Stack)
{
ItemToBeAdded = Plr->GetItemInterface()->FindItemLessMax(ItemID, Amt, false);
if(ItemToBeAdded != NULL)
{
ItemToBeAdded->ModUnsigned32Value(ITEM_FIELD_STACK_COUNT, Amt);
ItemToBeAdded->m_isDirty = true;
Plr->BroadcastMessage("%s%s x%u awarded for your kill!", MSG_COLOR_GOLD, ItemToBeAdded->GetProto()->Name1, Amt);
return;
}
}
for(uint32 i = 1;i <= Amt;i++)
{
ItemToBeAdded = objmgr.CreateItem(ItemID, Plr);
if(ItemToBeAdded == NULL)
return; // :O it didn't work!
Slot = Plr->GetItemInterface()->FindFreeInventorySlot(ItemToBeAdded->GetProto());
if(Slot.Result)
{
Plr->GetItemInterface()->SafeAddItem(ItemID, Slot.ContainerSlot, Slot.Slot);
Plr->BroadcastMessage("%s%s x1 awarded for you kill!", MSG_COLOR_GOLD, ItemToBeAdded->GetProto()->Name1);
}
else
Plr->SendAreaTriggerMessage("You have no free inventory slots, aborting.");
}
}
void OnKill(Player* pPlayer, Player* pVictim)
{
if(pPlayer->GetMapId() != 560 || pVictim->GetMapId() != 560)
return; // Both players must be at map 560 for the killer to receive the item
if(pVictim->getLevel() < pPlayer->getLevel())
return; // Killer receives item only from killing a player their level and above
if(pPlayer->GetLowGUID() == pVictim->GetLowGUID())
return; // If player suicides, no award is given
if(pPlayer->GetTeam() == pVictim->GetTeam())
return; // Award only from killing the other faction
AddItem(pPlayer, 29434, 1, true);
// "29434" is the item ID (change it if you want)
// "1" is the amount of the item to give (change it if you want)
// and the "true" means that we stack the item
// Change "true" to "false" if you want the item to not stack when it enters your inventory
return;
}
void SetupItemRewardScript(ScriptMgr* mgr)
{
mgr->register_hook(SERVER_HOOK_EVENT_ON_KILL_PLAYER, (void*)OnKill);
}
Read through the script. I have put the comments in green text to make it easier to edit and understand :)
Hope this is useful to some people.
Cheers,
Alvanaar