Advertisement
EmuDevs

Emudevs: TrinityCore - BountyHunter Script Redone

Aug 18th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.20 KB | None | 0 0
  1. /*
  2.      Bounty Hunter by Sdyess
  3.      Redone by Tommy because it was shit
  4.      <http://emudevs.com>
  5. */
  6.  
  7. enum BountyPrice
  8. {
  9.     BOUNTY_PRICE_1 = 20,
  10.     BOUNTY_PRICE_2 = 40,
  11.     BOUNTY_PRICE_3 = 100,
  12.     BOUNTY_PRICE_4 = 200,
  13. };
  14.  
  15. void BountyAlert(const char* name, int msg)
  16. {
  17.     std::string message;
  18.     if(msg == 1)
  19.     {
  20.         message = "A bounty has been placed on ";
  21.         message += name;
  22.         message += ". Kill them immediately to collect the reward!";
  23.     }
  24.     else if(msg == 2)
  25.     {
  26.         message = "The bounty on ";
  27.         message += name;
  28.         message += " has been collected!";
  29.     }
  30.     sWorld->SendServerMessage(SERVER_MSG_STRING, message.c_str(), 0);
  31. }
  32.  
  33. class BountyHunter : public CreatureScript
  34. {
  35. public:
  36.     BountyHunter() : CreatureScript("BountyHunter"){}
  37.  
  38.     bool OnGossipHello(Player* player, Creature* creature)
  39.     {
  40.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "I would like to place a bounty!", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
  41.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, "Show me the bounty list!", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
  42.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, "Nevermind..", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+3);
  43.         if (player->IsGameMaster())
  44.             player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, "Wipe Bounties", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+4);
  45.         player->SEND_GOSSIP_MENU(1, creature->GetGUID());
  46.         return true;
  47.     }
  48.      
  49.     bool OnGossipSelect(Player* player, Creature* creature, uint32 /* sender */, uint32 actions)
  50.     {
  51.         player->PlayerTalkClass->ClearMenus();
  52.         switch (actions)
  53.         {
  54.             case GOSSIP_ACTION_INFO_DEF+1:
  55.                 player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, "I would like to place a 20g bounty.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+5, "", 0, true);
  56.                 player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, "I would like to place a 40g bounty.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+6, "", 0, true);
  57.                 player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, "I would like to place a 100g bounty.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+7, "", 0, true);
  58.                 player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_BATTLE, "I would like to place a 200g bounty.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+8, "", 0, true);
  59.                 player->SEND_GOSSIP_MENU(1, creature->GetGUID());
  60.                 break;
  61.             case GOSSIP_ACTION_INFO_DEF+2:
  62.             {
  63.                 QueryResult result = CharacterDatabase.Query("SELECT * FROM bounties");
  64.                                            
  65.                 if (!result)
  66.                 {
  67.                     player->CLOSE_GOSSIP_MENU();
  68.                     return false;
  69.                 }
  70.  
  71.                 player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Bounties: ", GOSSIP_SENDER_MAIN, 1);
  72.  
  73.                 do
  74.                 {
  75.                     Field* fields = result->Fetch();
  76.                     std::string option;
  77.                     QueryResult result2 = CharacterDatabase.PQuery("SELECT `name` FROM characters WHERE guid='%u' LIMIT 10", fields[0].GetUInt64());
  78.                     if (!result2)
  79.                         return false;
  80.  
  81.                     Field* names = result2->Fetch();
  82.                     option = names[0].GetString();
  83.                     option += " ";
  84.                     option += fields[1].GetString();
  85.                     option += " gold";
  86.  
  87.                     player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, option.c_str(), GOSSIP_SENDER_MAIN, 1);
  88.                 }while(result->NextRow());
  89.                 player->SEND_GOSSIP_MENU(1, creature->GetGUID());  
  90.             }break;
  91.             case GOSSIP_ACTION_INFO_DEF+3:
  92.                 player->CLOSE_GOSSIP_MENU();
  93.                 break;
  94.             case GOSSIP_ACTION_INFO_DEF+4:
  95.                 CharacterDatabase.Execute("TRUNCATE TABLE bounties");
  96.                 player->CLOSE_GOSSIP_MENU();
  97.                 break;
  98.         }
  99.         return true;
  100.     }
  101.      
  102.     bool OnGossipSelectCode(Player* player, Creature* creature, uint32 /* sender */, uint32 actions, const char* code)
  103.     {
  104.         player->PlayerTalkClass->ClearMenus();
  105.        
  106.         if (islower(code[0]))
  107.             toupper(code[0]);
  108.      
  109.         if (passChecks(player, code))
  110.         {
  111.             Player* hunted = sObjectAccessor->FindPlayerByName(code);
  112.             switch (actions)
  113.             {
  114.                 case GOSSIP_ACTION_INFO_DEF+5:
  115.                 {
  116.                     if (HasCurrency(player, BOUNTY_PRICE_1, 0))
  117.                     {
  118.                         CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u','20', '1')", hunted->GetGUID());
  119.                         BountyAlert(code, 1);
  120.                         FlagPlayer(code);
  121.                         player->CLOSE_GOSSIP_MENU();
  122.                     }                                      
  123.                 }break;        
  124.                 case GOSSIP_ACTION_INFO_DEF+6:
  125.                 {
  126.                     if (HasCurrency(player, BOUNTY_PRICE_2, 0))
  127.                     {
  128.                         CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '40', '2')", hunted->GetGUID());
  129.                         BountyAlert(code, 1);
  130.                         FlagPlayer(code);
  131.                         player->CLOSE_GOSSIP_MENU();
  132.                     }                                          
  133.                 }break;
  134.                 case GOSSIP_ACTION_INFO_DEF+7:
  135.                 {
  136.                     if (HasCurrency(player, BOUNTY_PRICE_3, 0))
  137.                     {
  138.                         CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '100', '3')", hunted->GetGUID());
  139.                         BountyAlert(code, 1);
  140.                         FlagPlayer(code);
  141.                         player->CLOSE_GOSSIP_MENU();
  142.                     }                                          
  143.                 }break;
  144.                 case GOSSIP_ACTION_INFO_DEF+8:
  145.                 {
  146.                     if (HasCurrency(player, BOUNTY_PRICE_4, 0))
  147.                     {
  148.                         CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '200', '4')", hunted->GetGUID());
  149.                         BountyAlert(code, 1);
  150.                         FlagPlayer(code);
  151.                         player->CLOSE_GOSSIP_MENU();
  152.                     }        
  153.                 }break;
  154.            }
  155.        }
  156.         else
  157.             player->CLOSE_GOSSIP_MENU();
  158.         return true;
  159.     }
  160.  
  161.     bool HasCurrency(Player* player, uint32 required, int currency)
  162.     {
  163.         uint32 currentmoney = player->GetMoney();
  164.         uint32 requiredmoney = (required * 10000);
  165.         if(currentmoney < requiredmoney)
  166.         {
  167.             player->GetSession()->SendNotification("You don't have enough gold!");
  168.             return false;
  169.         }
  170.         player->SetMoney(currentmoney - requiredmoney);
  171.         return true;
  172.     }
  173.  
  174.     bool passChecks(Player* player, const char* name)
  175.     {
  176.         Player* hunted = sObjectAccessor->FindPlayerByName(name);
  177.         if(!hunted)
  178.         {
  179.             player->GetSession()->SendNotification("The player is offline or doesn't exist!");
  180.             return false;
  181.         }
  182.            
  183.         QueryResult result = CharacterDatabase.PQuery("SELECT * FROM bounties WHERE guid ='%u'", hunted->GetGUID());
  184.         if(result)
  185.         {
  186.             player->GetSession()->SendNotification("This player already has a bounty on them!");
  187.             return false;
  188.         }
  189.  
  190.         if(player->GetGUID() == hunted->GetGUID())
  191.         {
  192.             player->GetSession()->SendNotification("You cannot set a bounty on yourself!");
  193.             return false;
  194.         }
  195.         return true;
  196.     }
  197.  
  198.     void FlagPlayer(const char* name)
  199.     {
  200.         Player* hunted = sObjectAccessor->FindPlayerByName(name);
  201.         hunted->SetPvP(true);
  202.         hunted->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);
  203.     }
  204. };
  205.  
  206. class BountyKills : public PlayerScript
  207. {
  208. public:
  209.     BountyKills() : PlayerScript("BountyKills"){}
  210.      
  211.     void OnPVPKill(Player* killer, Player* victim)
  212.     {
  213.         if(killer->GetGUID() == victim->GetGUID())
  214.             return;
  215.  
  216.         QueryResult result = CharacterDatabase.PQuery("SELECT * FROM bounties WHERE guid='%u'", victim->GetGUID());
  217.         if(!result)
  218.             return;
  219.      
  220.         Field* fields = result->Fetch();
  221.         switch(fields[2].GetUInt64())
  222.         {
  223.             case 1:
  224.                 killer->SetMoney(killer->GetMoney() + (BOUNTY_PRICE_1 * 10000));
  225.                 break;
  226.             case 2:
  227.                 killer->SetMoney(killer->GetMoney() + (BOUNTY_PRICE_2 * 10000));
  228.                 break;
  229.             case 3:
  230.                 killer->SetMoney(killer->GetMoney() + (BOUNTY_PRICE_3 * 10000));
  231.                 break;
  232.             case 4:
  233.                 killer->SetMoney(killer->GetMoney() + (BOUNTY_PRICE_4 * 10000));
  234.                 break;
  235.         }
  236.         CharacterDatabase.PExecute("DELETE FROM bounties WHERE guid='%u'", victim->GetGUID());
  237.         BountyAlert(victim->GetName().c_str(), 2);
  238.     }          
  239. };
  240.  
  241. void AddSC_bounty()
  242. {
  243.     new BountyHunter();
  244.     new BountyKills();
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement