[C++] Efficient Arena Rewards (2v2 & 3v3 5v5)

Need a tutorial to follow?
Post Reply

Topic author
XxTryxX
Member
Posts: 6
Joined: March 17th, 2018, 4:08 am

March 18th, 2018, 2:50 am

What it does: It adds a specific item upon winning a rated arena match.

i did at Trinitycore Latest rev, i think it will worked and older one, you must test it if you got any, Error in include or somethings please just report on here

Where to implement: ArenaTeam.cpp (src/server/game/Battlegrounds/ArenaTeam.cpp)

First off, find the function void ArenaTeam::MemberWon.
Under the line: itr->WeekWins += 1;
Add

Code: Select all

 
            if (Type == ARENA_TEAM_2v2)
            {
                player->AddItem(1337, 1);
            }
            else if (Type == ARENA_TEAM_3v3)
            {
                player->AddItem(1337, 1);
            }
                  else if (Type == ARENA_TEAM_5v5)
            {
                player->AddItem(1337, 1);
            }

Save & Compile!
(If you want to change the item ID, change 1337 to the item ID and to change the amount change the 1 to a different number of items to be given )
Example:
(194888, 5)
Adds five times 194888, which could be a custom coin perhaps on your server?

http://prntscr.com/isr919
Last edited by XxTryxX on March 18th, 2018, 7:33 am, edited 3 times in total.

User avatar

Krill
Member
Posts: 4
Joined: March 12th, 2018, 5:22 pm

March 18th, 2018, 2:56 am

Could maybe look into adding in a % table or something.. like instead of dropping just one item, you could define multiple items in a array, along with their % to drop individually, or % in the entire array.


Topic author
XxTryxX
Member
Posts: 6
Joined: March 17th, 2018, 4:08 am

March 18th, 2018, 2:58 am

yeah possible to, just a new at C++ trying to learn Somethings

User avatar

Meltie
Administrator
Posts: 35
Joined: March 9th, 2018, 11:18 am
Contact:

March 18th, 2018, 6:56 am

Make sure to add a tag to your post, so people know what core it works with.

It's impossible to work hard for something, you don't enjoy!
- Keiko Ayano

User avatar

Jameyboor
Member
Posts: 1
Joined: March 17th, 2018, 12:51 pm

March 18th, 2018, 8:27 am

The usual way you implement a few items with drop chances 0 - 100 % is to use a weighted map like so:

Code: Select all

using map_t = std::map<uint32, std::pair<uint32, uint32>>;

void InsertItemChance(map_t& container, uint32 chance, uint32 itemId, uint32 count)
{
	int start = 0;
	if(container.size())
	{
		auto last_itr = container.rbegin();
		start = last_itr->first;
	}
	container.emplace(std::make_pair(start + chance, std::make_pair(itemId, count)));
}

auto GetRandomItem(map_t& container) -> std::pair<uint32, uint32>
{
	if(!container.size())
	  return {};
	uint32 rand = urand(0, 100);
	map_t::iterator itr = container.find(rand);
	if(itr == container.end())
	  itr = container.upper_bound(rand);
	  
	if(itr == container.end())
	  return {};
	return itr->second;
}
And then use it like so for example

Code: Select all

map_t items;
InsertItemChance(items, 25, 1, 1);
InsertItemChance(items, 30, 2, 1);
InsertItemChance(items, 10, 3, 1);
InsertItemChance(items, 15, 4, 1);

auto [itemId, count] = GetRandomItem(items);

if(itemId && count)
  player->AddItem(itemId, count);

User avatar

Infamous
Moderator
Posts: 15
Joined: March 10th, 2018, 10:21 am
Location: Long Beach, CA

March 18th, 2018, 9:48 am

very useful, especially for custom or instant level fun servers thanks for sharing!


Topic author
XxTryxX
Member
Posts: 6
Joined: March 17th, 2018, 4:08 am

March 18th, 2018, 10:56 am

thx usefull, aswell as i said i am new to at C++

User avatar

Meltie
Administrator
Posts: 35
Joined: March 9th, 2018, 11:18 am
Contact:

March 18th, 2018, 11:03 am

You'll get better at C++ as time goes on. Took me the longest time to understand it, to be able to write some code. Keep up the good work though. Would love to see more of your work as you write it.

It's impossible to work hard for something, you don't enjoy!
- Keiko Ayano

Post Reply