Advertisement
Guest User

[TrinityCore]: Bounty Hunter, By Tommy.

a guest
Jul 6th, 2012
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.28 KB | None | 0 0
  1. /*******************************************************************************************
  2. *                        __                           __ _                                 *
  3. *                     /\ \ \___  _ __ ___  ___  ___  / _| |_                               *
  4. *                    /  \/ / _ \| '_ ` _ \/ __|/ _ \| |_| __|                              *
  5. *                   / /\  / (_) | | | | | \__ \ (_) |  _| |_                               *
  6. *                   \_\ \/ \___/|_| |_| |_|___/\___/|_|  \__|   - www.Nomsoftware.com -    *
  7. *                               The policy of Nomsoftware states: Releasing our software   *
  8. *                               or any other files are protected. You cannot re-release    *
  9. *                               anywhere unless you were given permission.                 *
  10. *                           (C) Nomsoftware 'Nomsoft' 2011-2012. All rights reserved.      *
  11. ********************************************************************************************/
  12. /**********************************************************
  13. **********************************************************
  14.  *                      Title:                          *
  15.   *                 Bounty Hunter                      *
  16.    *        Scripted for the Nomsoft Server           *
  17.     *                                                *
  18.      *            Scripted by: Tommy                *
  19.       *     (C)Nomsoftware 'Nomsoft' 2012          *
  20.        *-----------------------------------------*/
  21. #include "ScriptPCH.h"
  22. #include <map>
  23.  
  24. using namespace std;
  25.  
  26. #define MSG_PLACE_BOUNTY "I would like to place a bounty. [10g]"
  27.  
  28. /* Bounty Misc */
  29. void DoSendMessageToWorld(int msg, string name, string playerName)
  30. {
  31.     ostringstream ss;
  32.     if (msg == 1)
  33.     {
  34.         ss << "|cffFF0000A Bounty has been placed on "
  35.             << name.c_str()
  36.             << "'s head!|r";
  37.     }
  38.     else if (msg == 2)
  39.     {
  40.         ss << "|cffFFA500Increased the price on "
  41.             << name.c_str()
  42.             << "'s head!|r";
  43.     }
  44.     else if (msg == 3)
  45.     {
  46.         ss << "|cffFF0000 "
  47.             << playerName.c_str()
  48.             << " has killed "
  49.             << name.c_str()
  50.             << ", a bounty target!";
  51.     }
  52.     sWorld->SendGlobalText(ss.str().c_str(), NULL);
  53. }
  54.  
  55. /* Bounty Enumeration */
  56. enum eGold
  57. {
  58.     BOUNTY_AMOUNT_GOLD = 100000
  59. };
  60.  
  61. /* Bounty Map */
  62. struct BountyInfo
  63. {
  64.     string name;
  65.     string bounty;
  66.     uint64 hunted;
  67.     uint64 hunter;
  68.     uint32 gold;
  69. };
  70.  
  71. map<uint64, BountyInfo> Bounty;
  72.  
  73. class npc_b_hunter : public CreatureScript
  74. {
  75.     public:
  76.         npc_b_hunter() : CreatureScript("npc_bounty_hunter") { }
  77.  
  78.         bool OnGossipHello(Player * player, Creature * creature)
  79.         {
  80.             player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, MSG_PLACE_BOUNTY, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1, "", 0, true);
  81.             if(!Bounty.empty())
  82.                 player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Show Bounty List", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
  83.             player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, "Nevermind..", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+4);
  84.             player->SEND_GOSSIP_MENU(1, creature->GetGUID());
  85.             return true;
  86.         }
  87.  
  88.         bool OnGossipSelect(Player * player, Creature * creature, uint32 sender, uint32 actions)
  89.         {
  90.             player->PlayerTalkClass->ClearMenus();
  91.             if(sender != GOSSIP_SENDER_MAIN)
  92.                 return false;
  93.  
  94.             switch(actions)
  95.             {
  96.                case GOSSIP_ACTION_INFO_DEF+2:
  97.                    for(map<uint64, BountyInfo>::const_iterator i = Bounty.begin(); i != Bounty.end(); ++i)
  98.                        ChatHandler(player).PSendSysMessage("Current Bounties: \n Name: %s, Money: %u, Bounty: %s", i->second.name.c_str(), i->second.gold, i->second.bounty.c_str());
  99.                    player->PlayerTalkClass->SendCloseGossip();
  100.                    break;
  101.  
  102.                case GOSSIP_ACTION_INFO_DEF+4:
  103.                    player->PlayerTalkClass->SendCloseGossip();
  104.                    break;
  105.             }
  106.             return true;
  107.         }
  108.  
  109.         bool OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 action, const char* code)
  110.         {
  111.             player->PlayerTalkClass->ClearMenus();
  112.             if(sender != GOSSIP_SENDER_MAIN)
  113.                 return false;
  114.  
  115.             string name = code;
  116.             Player * hunted = NULL;
  117.  
  118.             switch(action)
  119.             {
  120.                case GOSSIP_ACTION_INFO_DEF+1:
  121.                    for(map<uint64, BountyInfo>::const_iterator i = Bounty.begin(); i != Bounty.end(); ++i)
  122.                    {
  123.                        if(i->second.bounty == player->GetName())
  124.                        {
  125.                            ChatHandler(player).SendSysMessage("You have already placed a bounty!");
  126.                            player->PlayerTalkClass->SendCloseGossip();
  127.                            return false;
  128.                        }
  129.  
  130.                        if(i->second.hunted == player->GetGUID())
  131.                        {
  132.                            ChatHandler(player).SendSysMessage("You cannot place a bounty if you're being hunted!");
  133.                            player->PlayerTalkClass->SendCloseGossip();
  134.                            return false;
  135.                        }
  136.  
  137.                        if(i->second.hunted == hunted->GetGUID())
  138.                        {
  139.                            Bounty[i->second.hunter].gold += BOUNTY_AMOUNT_GOLD;
  140.                            ChatHandler(player).PSendSysMessage("A hunter already made his mark on %s! So, the price for this bounty went up!", i->second.name.c_str());
  141.                            DoSendMessageToWorld(2, i->second.name, "");
  142.                            player->PlayerTalkClass->SendCloseGossip();
  143.                            return false;
  144.                        }
  145.                    }
  146.  
  147.                    if(player->GetMoney() >= BOUNTY_AMOUNT_GOLD)
  148.                    {
  149.                        player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, MSG_PLACE_BOUNTY, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1, "", 0, true);
  150.                        player->ModifyMoney(-BOUNTY_AMOUNT_GOLD);
  151.                    }
  152.                    else
  153.                    {
  154.                        ChatHandler(player).SendSysMessage("You don't have enough gold!");
  155.                        player->PlayerTalkClass->SendCloseGossip();
  156.                        return false;
  157.                    }
  158.                    if(!name.empty())
  159.                        hunted = sObjectAccessor->FindPlayerByName(name.c_str());
  160.  
  161.                    if(name == player->GetName())
  162.                    {
  163.                        ChatHandler(player).SendSysMessage("You cannot place a bounty on yourself!");
  164.                        player->PlayerTalkClass->SendCloseGossip();
  165.                        return false;
  166.                    }
  167.  
  168.                    if(!hunted)
  169.                    {
  170.                        ChatHandler(player).PSendSysMessage("Player %s is not online.", name.c_str());
  171.                        player->PlayerTalkClass->SendCloseGossip();
  172.                        return false;
  173.                    }
  174.                    Bounty[hunted->GetGUID()].hunted = hunted->GetGUID();
  175.                    Bounty[hunted->GetGUID()].hunter = player->GetGUID();
  176.                    Bounty[hunted->GetGUID()].gold = BOUNTY_AMOUNT_GOLD;
  177.                    Bounty[hunted->GetGUID()].name = name.c_str();
  178.                    Bounty[hunted->GetGUID()].bounty = player->GetName();
  179.                    ChatHandler(player).PSendSysMessage("|cffFF0000Bounty was placed on %s!|r", name.c_str());
  180.                    player->Whisper("I placed a Bounty on you!", LANG_UNIVERSAL, hunted->GetGUID());
  181.                    DoSendMessageToWorld(1, name.c_str(), "");
  182.                    player->PlayerTalkClass->SendCloseGossip();
  183.                    break;
  184.             }
  185.             hunted = NULL;
  186.             name = "";
  187.             return false;
  188.         }
  189. };
  190.  
  191. class bounty_kills : public PlayerScript
  192. {
  193.    public:
  194.        bounty_kills() : PlayerScript("bounty_kills") { }
  195.  
  196.        void OnPVPKill(Player * killer, Player * victim)
  197.        {
  198.            if(killer->GetGUID() == victim->GetGUID() || Bounty.empty())
  199.                return;
  200.  
  201.            for(map<uint64, BountyInfo>::const_iterator i = Bounty.begin(); i != Bounty.end(); ++i)
  202.            {
  203.                if(i->second.hunted == victim->GetGUID())
  204.                {
  205.                    killer->ModifyMoney(Bounty[victim->GetGUID()].gold);
  206.                    ChatHandler(killer).PSendSysMessage("Added %u gold for your kill!", Bounty[victim->GetGUID()].gold);
  207.                    Bounty.erase(victim->GetGUID());
  208.                    DoSendMessageToWorld(3, victim->GetName(), killer->GetName());
  209.                }
  210.            }
  211.        }
  212. };
  213.  
  214. void AddSC_bounties_hunters()
  215. {
  216.     new npc_b_hunter;
  217.     new bounty_kills;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement