Advertisement
randy336

Bounty Hunter - Trinity Core

Jan 30th, 2013
968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.08 KB | None | 0 0
  1. #include "ScriptPCH.h"
  2. #include <cstring>
  3.  
  4. #define SET_CURRENCY 0  //0 for gold, 1 for honor, 2 for tokens
  5. #define TOKEN_ID 0 // token id
  6.  
  7. #if SET_CURRENCY == 0
  8. #define BOUNTY_1 "I would like to place a 20g bounty."
  9. #define BOUNTY_2 "I would like to place a 40g bounty."
  10. #define BOUNTY_3 "I would like to place a 100g bounty."
  11. #define BOUNTY_4 "I would like to place a 200g bounty."
  12. #define BOUNTY_5 "I would like to place a 300g bounty."
  13. #define BOUNTY_6 "I would like to place a 400g bounty."
  14. #define BOUNTY_7 "I would like to place a 500g bounty."
  15. #define BOUNTY_8 "I would like to place a 700g bounty."
  16. #endif
  17. #if SET_CURRENCY == 1
  18. #define BOUNTY_1 "I would like to place a 20 honor bounty."
  19. #define BOUNTY_2 "I would like to place a 40 honor bounty."
  20. #define BOUNTY_3 "I would like to place a 100 honor bounty."
  21. #define BOUNTY_4 "I would like to place a 200 honor bounty."
  22. #endif
  23. #if SET_CURRENCY == 2
  24. #define BOUNTY_1 "I would like to place a 1 token bounty."
  25. #define BOUNTY_2 "I would like to place a 3 token bounty."
  26. #define BOUNTY_3 "I would like to place a 5 token bounty."
  27.  
  28. #endif
  29.  
  30. #define PLACE_BOUNTY "I would like to place a bounty."
  31. #define LIST_BOUNTY "List the current bounties."
  32. #define NVM "Nevermind"
  33. #define WIPE_BOUNTY "Wipe bounties"
  34.  
  35.  
  36.  
  37.  
  38. #if SET_CURRENCY != 2
  39. //these are just visual prices, if you want to to change the real one, edit the sql further below
  40. enum BountyPrice
  41. {
  42.     BOUNTY_PRICE_1 = 20,
  43.     BOUNTY_PRICE_2 = 40,
  44.     BOUNTY_PRICE_3 = 100,
  45.     BOUNTY_PRICE_4 = 200,
  46.     BOUNTY_PRICE_5 = 300,
  47.     BOUNTY_PRICE_6 = 400,
  48.     BOUNTY_PRICE_7 = 500,
  49.     BOUNTY_PRICE_8 = 700,
  50. };
  51. #else
  52. enum BountyPrice
  53. {
  54.     BOUNTY_PRICE_1 = 1,
  55.     BOUNTY_PRICE_2 = 3,
  56.     BOUNTY_PRICE_3 = 5,
  57.     BOUNTY_PRICE_4 = 10,
  58. };
  59. #endif
  60.  
  61. bool passChecks(Player * pPlayer, const char * name)
  62. {
  63.  
  64.     Player * pBounty = sObjectAccessor->FindPlayerByName(name);
  65.     WorldSession * m_session = pPlayer->GetSession();
  66.     if(!pBounty)
  67.     {
  68.         m_session->SendNotification("The player is offline or doesn't exist!");
  69.         return false;
  70.     }
  71.     QueryResult result = CharacterDatabase.PQuery("SELECT * FROM bounties WHERE guid ='%u'", pBounty->GetGUID());
  72.     if(result)
  73.     {
  74.         m_session->SendNotification("This player already has a bounty on them!");
  75.         return false;
  76.     }
  77.     if(pPlayer->GetGUID() == pBounty->GetGUID())
  78.     {
  79.         m_session->SendNotification("You cannot set a bounty on yourself!");
  80.         return false;
  81.     }
  82.     return true;
  83. }
  84.  
  85. void alertServer(const char * name, int msg)
  86. {
  87.     std::string message;
  88.     if(msg == 1)
  89.     {
  90.         message = "A bounty has been placed on ";
  91.         message += name;
  92.         message += ". Kill them immediately to collect the reward!";
  93.     }
  94.     else if(msg == 2)
  95.     {
  96.         message = "The bounty on ";
  97.         message += name;
  98.         message += " has been collected!";
  99.     }
  100.     sWorld->SendServerMessage(SERVER_MSG_STRING, message.c_str(), 0);
  101. }
  102.  
  103.  
  104. bool hasCurrency(Player * pPlayer, uint32 required, int currency)
  105. {
  106.     WorldSession *m_session = pPlayer->GetSession();
  107.     switch(currency)
  108.     {
  109.         case 0: //gold
  110.             {
  111.             uint32 currentmoney = pPlayer->GetMoney();
  112.             uint32 requiredmoney = (required * 10000);
  113.             if(currentmoney < requiredmoney)
  114.             {
  115.                 m_session->SendNotification("You don't have enough gold!");
  116.                 return false;
  117.             }
  118.             pPlayer->SetMoney(currentmoney - requiredmoney);
  119.             break;
  120.             }
  121.         case 1: //honor
  122.             {
  123.             uint32 currenthonor = pPlayer->GetHonorPoints();
  124.             if(currenthonor < required)
  125.             {
  126.                 m_session->SendNotification("You don't have enough honor!");
  127.                 return false;
  128.             }
  129.             pPlayer->SetHonorPoints(currenthonor - required);
  130.             break;
  131.             }
  132.         case 2: //tokens
  133.             {
  134.             if(!pPlayer->HasItemCount(TOKEN_ID, required))
  135.             {
  136.                 m_session->SendNotification("You don't have enough tokens!");
  137.                 return false;
  138.             }
  139.             pPlayer->DestroyItemCount(TOKEN_ID, required, true, false);
  140.             break;
  141.             }
  142.  
  143.     }
  144.     return true;
  145. }
  146.  
  147. void flagPlayer(const char * name)
  148. {
  149.     Player * pBounty = sObjectAccessor->FindPlayerByName(name);
  150.     pBounty->SetPvP(true);
  151.     pBounty->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);
  152. }
  153.  
  154. class BountyHunter : public CreatureScript
  155. {
  156.     public:
  157.         BountyHunter() : CreatureScript("BountyHunter"){}
  158.         bool OnGossipHello(Player * Player, Creature * Creature)
  159.         {
  160.             Player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, PLACE_BOUNTY, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
  161.             Player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, LIST_BOUNTY, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
  162.             Player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, NVM, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+3);
  163.             if ( Player->isGameMaster() )
  164.                 Player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, WIPE_BOUNTY, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+4);
  165.  
  166.             Player->PlayerTalkClass->SendGossipMenu(907, Creature->GetGUID());
  167.             return true;
  168.         }
  169.  
  170.         bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 /*uiSender*/, uint32 uiAction)
  171.         {
  172.             pPlayer->PlayerTalkClass->ClearMenus();
  173.             switch(uiAction)
  174.             {
  175.                 case GOSSIP_ACTION_INFO_DEF+1:
  176.                 {
  177.                     pPlayer->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, BOUNTY_1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+5, "", 0, true);
  178.                     pPlayer->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, BOUNTY_2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+6, "", 0, true);
  179.                     pPlayer->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, BOUNTY_3, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+7, "", 0, true);
  180.                     pPlayer->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, BOUNTY_4, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+8, "", 0, true);
  181.                     pPlayer->PlayerTalkClass->SendGossipMenu(365, pCreature->GetGUID());
  182.                     break;
  183.                 }
  184.                 case GOSSIP_ACTION_INFO_DEF+2:
  185.                 {
  186.                     QueryResult Bounties = CharacterDatabase.PQuery("SELECT * FROM bounties");
  187.                    
  188.                     if(!Bounties)
  189.                     {
  190.                         pPlayer->PlayerTalkClass->SendCloseGossip();
  191.                         return false;
  192.                     }
  193. #if SET_CURRENCY == 0
  194.                     if( Bounties->GetRowCount() > 1)
  195.                     {
  196.                         pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Bounties: ", GOSSIP_SENDER_MAIN, 1);
  197.                         do
  198.                         {
  199.                             Field * fields = Bounties->Fetch();
  200.                             std::string option;
  201.                             QueryResult name = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid='%u'", fields[0].GetUInt64());
  202.                             Field * names = name->Fetch();
  203.                             option = names[0].GetString();
  204.                             option +=" ";
  205.                             option += fields[1].GetString();
  206.                             option += " gold";
  207.                             pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, option, GOSSIP_SENDER_MAIN, 1);
  208.                         }while(Bounties->NextRow());
  209.                     }
  210.                     else
  211.                     {
  212.                         pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Bounties: ", GOSSIP_SENDER_MAIN, 1);
  213.                         Field * fields = Bounties->Fetch();
  214.                         std::string option;
  215.                         QueryResult name = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid='%u'", fields[0].GetUInt64());
  216.                         Field * names = name->Fetch();
  217.                         option = names[0].GetString();
  218.                         option +=" ";
  219.                         option += fields[1].GetString();
  220.                         option += " gold";
  221.                         pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, option, GOSSIP_SENDER_MAIN, 1);
  222.                        
  223.                     }
  224. #endif
  225. #if SET_CURRENCY == 1
  226.                     if( Bounties->GetRowCount() > 1)
  227.                     {
  228.                         pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Bounties: ", GOSSIP_SENDER_MAIN, 1);
  229.                         do
  230.                         {
  231.                             Field * fields = Bounties->Fetch();
  232.                             std::string option;
  233.                             QueryResult name = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid='%u'", fields[0].GetUInt64());
  234.                             Field * names = name->Fetch();
  235.                             option = names[0].GetString();
  236.                             option +=" ";
  237.                             option += fields[1].GetString();
  238.                             option += " honor";
  239.                             pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, option, GOSSIP_SENDER_MAIN, 1);
  240.                         }while(Bounties->NextRow());
  241.                     }
  242.                     else
  243.                     {
  244.                         pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Bounties: ", GOSSIP_SENDER_MAIN, 1);
  245.                         Field * fields = Bounties->Fetch();
  246.                         std::string option;
  247.                         QueryResult name = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid='%u'", fields[0].GetUInt64());
  248.                         Field * names = name->Fetch();
  249.                         option = names[0].GetString();
  250.                         option +=" ";
  251.                         option += fields[1].GetString();
  252.                         option += " honor";
  253.                         pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, option, GOSSIP_SENDER_MAIN, 1);
  254.                        
  255.                     }
  256. #endif
  257. #if SET_CURRENCY == 2
  258.                     if( Bounties->GetRowCount() > 1)
  259.                     {
  260.                         pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Bounties: ", GOSSIP_SENDER_MAIN, 1);
  261.                         do
  262.                         {
  263.                             Field * fields = Bounties->Fetch();
  264.                             std::string option;
  265.                             QueryResult name = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid='%u'", fields[0].GetUInt64());
  266.                             Field * names = name->Fetch();
  267.                             option = names[0].GetString();
  268.                             option +=" ";
  269.                             option += fields[1].GetString();
  270.                             option += " coins";
  271.                             pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, option, GOSSIP_SENDER_MAIN, 1);
  272.                         }while(Bounties->NextRow());
  273.                     }
  274.                     else
  275.                     {
  276.                         pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Bounties: ", GOSSIP_SENDER_MAIN, 1);
  277.                         Field * fields = Bounties->Fetch();
  278.                         std::string option;
  279.                         QueryResult name = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid='%u'", fields[0].GetUInt64());
  280.                         Field * names = name->Fetch();
  281.                         option = names[0].GetString();
  282.                         option +=" ";
  283.                         option += fields[1].GetString();
  284.                         option += " coins";
  285.                         pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, option, GOSSIP_SENDER_MAIN, 1);
  286.                        
  287.                     }
  288. #endif
  289.                     pPlayer->PlayerTalkClass->SendGossipMenu(878, pCreature->GetGUID());
  290.                     break;
  291.                 }
  292.                 case GOSSIP_ACTION_INFO_DEF+3:
  293.                 {
  294.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  295.                     break;
  296.                 }
  297.                 case GOSSIP_ACTION_INFO_DEF+4:
  298.                 {
  299.                     CharacterDatabase.PExecute("TRUNCATE TABLE bounties");
  300.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  301.                     break;
  302.                 }
  303.             }
  304.             return true;
  305.         }
  306.  
  307.         bool OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 uiSender, uint32 uiAction, const char * code)
  308.         {
  309.             pPlayer->PlayerTalkClass->ClearMenus();
  310.             if ( uiSender == GOSSIP_SENDER_MAIN )
  311.             {
  312.                 if(islower(code[0]))
  313.                     toupper(code[0]);
  314.  
  315.                 if(passChecks(pPlayer, code))
  316.                 {
  317.                     Player * pBounty = sObjectAccessor->FindPlayerByName(code);
  318.                     switch (uiAction)
  319.                     {
  320.                         case GOSSIP_ACTION_INFO_DEF+5:
  321.                         {
  322.                             if(hasCurrency(pPlayer, BOUNTY_PRICE_1, SET_CURRENCY))
  323.                             {
  324.                                 #if SET_CURRENCY != 2
  325.                                 CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u','20', '1')", pBounty->GetGUID());
  326.                                 #else
  327.                                 CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u','1', '1')", pBounty->GetGUID());
  328.                                 #endif
  329.                                 alertServer(code, 1);
  330.                                 flagPlayer(code);
  331.                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  332.                             }
  333.                             break;
  334.                         }
  335.                            
  336.                         case GOSSIP_ACTION_INFO_DEF+6:
  337.                         {
  338.                             if(hasCurrency(pPlayer, BOUNTY_PRICE_2, SET_CURRENCY))
  339.                             {
  340.                                 #if SET_CURRENCY != 2
  341.                                 CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '40', '2')", pBounty->GetGUID());
  342.                                 #else
  343.                                 CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '3', '2')", pBounty->GetGUID());
  344.                                 #endif
  345.                                 alertServer(code, 1);
  346.                                 flagPlayer(code);
  347.                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  348.                             }
  349.                             break;
  350.                         }
  351.                         case GOSSIP_ACTION_INFO_DEF+7:
  352.                         {
  353.                             if(hasCurrency(pPlayer, BOUNTY_PRICE_3, SET_CURRENCY))
  354.                             {
  355.                                 #if SET_CURRENCY != 2
  356.                                 CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '100', '3')", pBounty->GetGUID());
  357.                                 #else
  358.                                 CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '5', '3')", pBounty->GetGUID());
  359.                                 #endif
  360.                                 alertServer(code, 1);
  361.                                 flagPlayer(code);
  362.                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  363.                             }
  364.                             break;
  365.                         }
  366.                         case GOSSIP_ACTION_INFO_DEF+8:
  367.                         {
  368.                             if(hasCurrency(pPlayer, BOUNTY_PRICE_4, SET_CURRENCY))
  369.                             {
  370.                                 #if SET_CURRENCY != 2
  371.                                 CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '200', '4')", pBounty->GetGUID());
  372.                                 #else
  373.                                 CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '10', '3')", pBounty->GetGUID());
  374.                                 #endif
  375.                                 alertServer(code, 1);
  376.                                 flagPlayer(code);
  377.                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  378.                             }
  379.                             break;
  380.                         }
  381.                        
  382.  
  383.                     }
  384.                 }
  385.                 else
  386.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  387.             }
  388.             return true;
  389.         }
  390. };
  391.  
  392.  
  393. class BountyKills : public PlayerScript
  394. {
  395.     public:
  396.         BountyKills() : PlayerScript("BountyKills"){}
  397.  
  398.         void OnPVPKill(Player * Killer, Player * Bounty)
  399.         {
  400.             if(Killer->GetGUID() == Bounty->GetGUID())
  401.                 return;
  402.  
  403.             QueryResult result = CharacterDatabase.PQuery("SELECT * FROM bounties WHERE guid='%u'", Bounty->GetGUID());
  404.             if(!result)
  405.                 return;
  406.  
  407.             Field * fields = result->Fetch();
  408.             #if SET_CURRENCY == 0
  409.                 switch(fields[2].GetUInt64())
  410.                 {
  411.                 case 1:
  412.                     Killer->SetMoney(Killer->GetMoney() + (BOUNTY_PRICE_1 * 10000));
  413.                     break;
  414.                 case 2:
  415.                     Killer->SetMoney(Killer->GetMoney() + (BOUNTY_PRICE_2 * 10000));
  416.                     break;
  417.                 case 3:
  418.                     Killer->SetMoney(Killer->GetMoney() + (BOUNTY_PRICE_3 * 10000));
  419.                     break;
  420.                 case 4:
  421.                     Killer->SetMoney(Killer->GetMoney() + (BOUNTY_PRICE_4 * 10000));
  422.                     break;
  423.                 case 5:
  424.                     Killer->SetMoney(Killer->GetMoney() + (BOUNTY_PRICE_5 * 10000));
  425.                     break;
  426.                 case 6:
  427.                     Killer->SetMoney(Killer->GetMoney() + (BOUNTY_PRICE_6 * 10000));
  428.                     break;
  429.                 case 7:
  430.                     Killer->SetMoney(Killer->GetMoney() + (BOUNTY_PRICE_7 * 10000));
  431.                     break;
  432.                 case 8:
  433.                     Killer->SetMoney(Killer->GetMoney() + (BOUNTY_PRICE_8 * 10000));
  434.                     break;
  435.                 }
  436.             #endif
  437.  
  438.             #if SET_CURRENCY == 1
  439.                 switch(fields[2].GetUInt64())
  440.                 {
  441.                 case 1:
  442.                     Killer->SetHonorPoints(Killer->GetHonorPoints() + (BOUNTY_PRICE_1));
  443.                     break;
  444.                 case 2:
  445.                     Killer->SetHonorPoints(Killer->GetHonorPoints() + (BOUNTY_PRICE_2));
  446.                     break;
  447.                 case 3:
  448.                     Killer->SetHonorPoints(Killer->GetHonorPoints() + (BOUNTY_PRICE_3));
  449.                     break;
  450.                 case 4:
  451.                     Killer->SetHonorPoints(Killer->GetHonorPoints()) + (BOUNTY_PRICE_4));
  452.                     break;
  453.                 case 5:
  454.                     Killer->SetHonorPoints(Killer->GetHonorPoints()) + (BOUNTY_PRICE_5));
  455.                     break;
  456.                 case 6:
  457.                     Killer->SetHonorPoints(Killer->GetHonorPoints()) + (BOUNTY_PRICE_6));
  458.                     break;
  459.                 case 7:
  460.                     Killer->SetHonorPoints(Killer->GetHonorPoints()) + (BOUNTY_PRICE_7));
  461.                     break; 
  462.                 case 8:
  463.                     Killer->SetHonorPoints(Killer->GetHonorPoints()) + (BOUNTY_PRICE_8));
  464.                     break;
  465.                 }
  466.             #endif
  467.  
  468.             #if SET_CURRENCY == 2
  469.                 switch(fields[2].GetUInt64())
  470.                 {
  471.                 case 1:
  472.                     Killer->AddItem(TOKEN_ID, BOUNTY_PRICE_1);
  473.                     break;
  474.                 case 2:
  475.                     Killer->AddItem(TOKEN_ID, BOUNTY_PRICE_2);
  476.                     break;
  477.                 case 3:
  478.                     Killer->AddItem(TOKEN_ID, BOUNTY_PRICE_3);
  479.                     break;
  480.  
  481.                 }
  482.             #endif
  483.             CharacterDatabase.PExecute("DELETE FROM bounties WHERE guid='%u'", Bounty->GetGUID());
  484.             alertServer(Bounty->GetName().c_str(), 2);
  485.         }
  486.  
  487.        
  488. };
  489.  
  490. void AddSC_BountyHunter()
  491. {
  492.     new BountyHunter();
  493.     new BountyKills();
  494. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement