Advertisement
Guest User

bhunter

a guest
Jun 28th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.75 KB | None | 0 0
  1. #include "ScriptPCH.h"
  2. #include <cstring>
  3.  
  4. #define BOUNTY_1 "I would like to place a 500 honor bounty."
  5. #define BOUNTY_2 "I would like to place a 5000 honor bounty."
  6. #define BOUNTY_3 "I would like to place a 15000 honor bounty."
  7. #define BOUNTY_4 "I would like to place a 30000 honor bounty."
  8.  
  9. #define PLACE_BOUNTY "I would like to place a bounty."
  10. #define LIST_BOUNTY "List the current bounties."
  11. #define NVM "Nevermind"
  12. #define WIPE_BOUNTY "Wipe bounties"
  13.  
  14. enum BountyPrices
  15. {
  16.     BOUNTY_PRICE_1 = 500,
  17.     BOUNTY_PRICE_2 = 5000,
  18.     BOUNTY_PRICE_3 = 15000,
  19.     BOUNTY_PRICE_4 = 30000,
  20. };
  21.  
  22. bool passChecks(Player * pPlayer, const char * name)
  23. {
  24.     Player* pBounty = ObjectAccessor::FindPlayerByName(name);
  25.  
  26.     WorldSession * m_session = pPlayer->GetSession();
  27.     if (!pBounty)
  28.     {
  29.         m_session->SendNotification("The player is offline or doesn't exist!");
  30.         return false;
  31.     }
  32.     QueryResult result = CharacterDatabase.PQuery("SELECT * FROM bounties WHERE guid ='%u'", pBounty->GetGUID());
  33.     if (result)
  34.     {
  35.         m_session->SendNotification("This player already has a bounty on them!");
  36.         return false;
  37.     }
  38.     if (pPlayer->GetGUID() == pBounty->GetGUID())
  39.     {
  40.         m_session->SendNotification("You cannot set a bounty on yourself!");
  41.         return false;
  42.     }
  43.     return true;
  44. }
  45.  
  46. void alertServer(const char * name, int msg)
  47. {
  48.     std::string message;
  49.     if (msg == 1)
  50.     {
  51.         message = "A bounty has been placed on ";
  52.         message += name;
  53.         message += ". Slay them to collect the reward!";
  54.     }
  55.     else if (msg == 2)
  56.     {
  57.         message = "The bounty on ";
  58.         message += name;
  59.         message += " has been collected!";
  60.     }
  61.     sWorld->SendServerMessage(SERVER_MSG_STRING, message.c_str(), 0);
  62. }
  63.  
  64. void flagPlayer(const char * name)
  65. {
  66.     Player * pBounty = ObjectAccessor::FindPlayerByName(name);
  67.     pBounty->SetPvP(true);
  68.     pBounty->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);
  69. }
  70.  
  71. class BountyHunter : public CreatureScript
  72. {
  73. public:
  74.     BountyHunter() : CreatureScript("BountyHunter"){}
  75.     bool OnGossipHello(Player * Player, Creature * Creature)
  76.     {
  77.         Player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, PLACE_BOUNTY, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
  78.         Player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, LIST_BOUNTY, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2);
  79.         Player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, NVM, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 3);
  80.         if (Player->IsGameMaster())
  81.             Player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, WIPE_BOUNTY, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 4);
  82.  
  83.         Player->PlayerTalkClass->SendGossipMenu(907, Creature->GetGUID());
  84.         return true;
  85.     }
  86.  
  87.     bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 /*uiSender*/, uint32 uiAction)
  88.     {
  89.         pPlayer->PlayerTalkClass->ClearMenus();
  90.         switch (uiAction)
  91.         {
  92.         case GOSSIP_ACTION_INFO_DEF + 1:
  93.         {
  94.             pPlayer->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, BOUNTY_1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 5, "", 0, true);
  95.             pPlayer->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, BOUNTY_2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 6, "", 0, true);
  96.             pPlayer->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, BOUNTY_3, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 7, "", 0, true);
  97.             pPlayer->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, BOUNTY_4, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 8, "", 0, true);
  98.             pPlayer->PlayerTalkClass->SendGossipMenu(365, pCreature->GetGUID());
  99.             break;
  100.         }
  101.         case GOSSIP_ACTION_INFO_DEF + 2:
  102.         {
  103.             QueryResult Bounties = CharacterDatabase.PQuery("SELECT * FROM bounties");
  104.  
  105.             if (!Bounties)
  106.             {
  107.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  108.                 return false;
  109.             }
  110.  
  111.             if (Bounties->GetRowCount() > 1)
  112.             {
  113.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Bounties: ", GOSSIP_SENDER_MAIN, 1);
  114.                 do
  115.                 {
  116.                     Field * fields = Bounties->Fetch();
  117.                     std::string option;
  118.                     QueryResult name = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid='%u'", fields[0].GetUInt64());
  119.                     Field * names = name->Fetch();
  120.                     option = names[0].GetString();
  121.                     option += " ";
  122.                     option += fields[1].GetString();
  123.                     option += " honor";
  124.                     pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, option, GOSSIP_SENDER_MAIN, 1);
  125.                 } while (Bounties->NextRow());
  126.             }
  127.             else
  128.             {
  129.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Bounties: ", GOSSIP_SENDER_MAIN, 1);
  130.                 Field * fields = Bounties->Fetch();
  131.                 std::string option;
  132.                 QueryResult name = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid='%u'", fields[0].GetUInt64());
  133.                 Field * names = name->Fetch();
  134.                 option = names[0].GetString();
  135.                 option += " ";
  136.                 option += fields[1].GetString();
  137.                 option += " honor";
  138.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, option, GOSSIP_SENDER_MAIN, 1);
  139.  
  140.             }
  141.  
  142.             pPlayer->PlayerTalkClass->SendGossipMenu(878, pCreature->GetGUID());
  143.             break;
  144.         }
  145.         case GOSSIP_ACTION_INFO_DEF + 3:
  146.         {
  147.             pPlayer->PlayerTalkClass->SendCloseGossip();
  148.             break;
  149.         }
  150.         case GOSSIP_ACTION_INFO_DEF + 4:
  151.         {
  152.             CharacterDatabase.PExecute("TRUNCATE TABLE bounties");
  153.             pPlayer->PlayerTalkClass->SendCloseGossip();
  154.             break;
  155.         }
  156.         }
  157.         return true;
  158.     }
  159.  
  160.     bool OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 uiSender, uint32 uiAction, const char * code)
  161.     {
  162.         pPlayer->PlayerTalkClass->ClearMenus();
  163.         if (uiSender == GOSSIP_SENDER_MAIN)
  164.         {
  165.             if (islower(code[0]))
  166.                 toupper(code[0]);
  167.  
  168.             if (passChecks(pPlayer, code))
  169.             {
  170.                 Player * pBounty = ObjectAccessor::FindPlayerByName(code);
  171.                 switch (uiAction)
  172.                 {
  173.                 case GOSSIP_ACTION_INFO_DEF + 5:
  174.                 {
  175.                     if (hasCurrency(pPlayer, BOUNTY_PRICE_1, 2))
  176.                     {
  177.                         CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u','20', '1')", pBounty->GetGUID());
  178.                         alertServer(code, 1);
  179.                         flagPlayer(code);
  180.                         pPlayer->PlayerTalkClass->SendCloseGossip();
  181.                     }
  182.                     break;
  183.                 }
  184.  
  185.                 case GOSSIP_ACTION_INFO_DEF + 6:
  186.                 {
  187.                     if (hasCurrency(pPlayer, BOUNTY_PRICE_2, 2))
  188.                     {
  189.                         CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '40', '2')", pBounty->GetGUID());
  190.                         alertServer(code, 1);
  191.                         flagPlayer(code);
  192.                         pPlayer->PlayerTalkClass->SendCloseGossip();
  193.                     }
  194.                     break;
  195.                 }
  196.                 case GOSSIP_ACTION_INFO_DEF + 7:
  197.                 {
  198.                     if (hasCurrency(pPlayer, BOUNTY_PRICE_3, 2))
  199.                     {
  200.                         CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '100', '3')", pBounty->GetGUID());
  201.                         alertServer(code, 1);
  202.                         flagPlayer(code);
  203.                         pPlayer->PlayerTalkClass->SendCloseGossip();
  204.                     }
  205.                     break;
  206.                 }
  207.                 case GOSSIP_ACTION_INFO_DEF + 8:
  208.                 {
  209.                     if (hasCurrency(pPlayer, BOUNTY_PRICE_4, 2))
  210.                     {
  211.                         CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '200', '4')", pBounty->GetGUID());
  212.                         alertServer(code, 1);
  213.                         flagPlayer(code);
  214.                         pPlayer->PlayerTalkClass->SendCloseGossip();
  215.                     }
  216.                     break;
  217.                 }
  218.  
  219.  
  220.                 }
  221.             }
  222.             else
  223.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  224.         }
  225.         return true;
  226.     }
  227. };
  228.  
  229.  
  230. class BountyKills : public PlayerScript
  231. {
  232. public:
  233.     BountyKills() : PlayerScript("BountyKills"){}
  234.  
  235.     void OnPVPKill(Player * Killer, Player * Bounty)
  236.     {
  237.         if (Killer->GetGUID() == Bounty->GetGUID())
  238.             return;
  239.  
  240.         QueryResult result = CharacterDatabase.PQuery("SELECT * FROM bounties WHERE guid='%u'", Bounty->GetGUID());
  241.         if (!result)
  242.             return;
  243.  
  244.         Field * fields = result->Fetch();
  245.         switch (fields[2].GetUInt64())
  246.         {
  247.         case 1:
  248.             Killer->AddItem(TOKEN_ID, BOUNTY_PRICE_1);
  249.             break;
  250.         case 2:
  251.             Killer->AddItem(TOKEN_ID, BOUNTY_PRICE_2);
  252.             break;
  253.         case 3:
  254.             Killer->AddItem(TOKEN_ID, BOUNTY_PRICE_3);
  255.             break;
  256.  
  257.         }
  258.         CharacterDatabase.PExecute("DELETE FROM bounties WHERE guid='%u'", Bounty->GetGUID());
  259.         alertServer(Bounty->GetName().c_str(), 2);
  260.     }
  261.  
  262.  
  263. };
  264.  
  265. void AddSC_BountyHunter()
  266. {
  267.     new BountyHunter();
  268.     new BountyKills();
  269. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement