PDA

View Full Version : [C++] PvP Token Reward System


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

Mazumion
04-23-2009, 04:07 AM
Nice +rep :D

Alvanaar
04-23-2009, 05:28 AM
:)
Thanks!

/bump

Mazumion
04-23-2009, 05:33 AM
No problem :D i might use this later on ^^

Ubbelol
04-23-2009, 05:34 AM
Did you make this? :O
Kewl

Alvanaar
04-23-2009, 07:12 AM
Yeah, I did! It took a while though. I'm not so pro.

tekkeryole
04-23-2009, 08:04 AM
forgot teh } at the end of your script :P

Alvanaar
04-23-2009, 08:34 AM
Ahh! Woops, it was in my original script, must've just cut it out when I put it in the [CODE]!

Thanks tekkeryole. :)

doublehex
04-23-2009, 10:13 AM
more suggestions:
if the item fails to add because of not enough slots, delete the item and save some memory

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 a player their level and above

if(pPlayer->GetLowGUID() == pVictim->GetLowGUID())
return; // If player s, no award is given

if(pPlayer->GetTeam() == pVictim->GetTeam())
return; // Award only from the other faction
//is there a missing if statement? or what are these brackets for?
{
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;
}
//} extra bracket
}


other than that nice job

Alvanaar
04-23-2009, 10:31 AM
Liking my fantastic scripting? *sarcasm*
Thanks doublehex!
I think I should get some sleep, lol.

doublehex
04-23-2009, 10:35 PM
:P one more fix then you should be good to go:
// Change "true" to "false" if you want the item to not stack when it enters your inventory
return;
//} you had 2 brackets, you only need 1
}

Alvanaar
04-23-2009, 11:46 PM
Yeah I noticed that one this morning. Thanks again!
:)

Jumpy09
05-11-2009, 08:47 AM
I got this information from QQrofl so all credits go to him, but I got it using this Script so I thought I would pass the information along.

Change This:
mgr->register_hook(SERVER_HOOK_EVENT_ON_PLAYER_KILL, (void*)&OnKill);

To This:
mgr->register_hook(SERVER_HOOK_EVENT_ON_KILL_PLAYER, (void*)OnKill);

The Server Hook has been changed in the last few weeks, so this should update it to ensure that it works with the latest changes. Thanks so much for the script, really comes in handy.

Alvanaar
05-11-2009, 09:03 AM
Oh, thanks heaps Jumpy! I actually remember gastricpenguin saying something about that, but I didn't take much notice.

Thanks again. Glad you like the script.

Alvanaar


265 views and only 13 posts, this isn't good enough. Come on people!

hjerpan
06-02-2009, 06:42 PM
Yeah, I did! It took a while though. I'm not so pro.

the additem void isnt by you else i think you didnt make it yourself fully you peaked from another script but i think its great cause i love when ppl releases stuff (even if i have a better one)

i Could release mine its an peek from spectres (modded for aspire shared pointers) and so on but i say like this +rep for the reason ur a nice guy just dont say you made it fully :P

Alvanaar
06-03-2009, 10:30 AM
Like I said above, before I edited it out with embarrassment, I made this one with some help from my brother, who now has moved away from home. :(
But I've improved my C++ now a lot. Don't need him anymore! :P


Thanks for the comments and rep hjerpan, I shall rep you back. :)

EDIT: And release yours too! :p I may be releasing a custom base capture zone script soon too.