Advertisement
julienanid

[Trinity] Bounty Hunter

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