- /*
- Bounty Hunter by Sdyess
- Redone by Tommy because it was shit
- <http://emudevs.com>
- */
- enum BountyPrice
- {
- BOUNTY_PRICE_1 = 20,
- BOUNTY_PRICE_2 = 40,
- BOUNTY_PRICE_3 = 100,
- BOUNTY_PRICE_4 = 200,
- };
- void BountyAlert(const char* name, int msg)
- {
- std::string message;
- if(msg == 1)
- {
- message = "A bounty has been placed on ";
- message += name;
- message += ". Kill them immediately to collect the reward!";
- }
- else if(msg == 2)
- {
- message = "The bounty on ";
- message += name;
- message += " has been collected!";
- }
- sWorld->SendServerMessage(SERVER_MSG_STRING, message.c_str(), 0);
- }
- class BountyHunter : public CreatureScript
- {
- public:
- BountyHunter() : CreatureScript("BountyHunter"){}
- bool OnGossipHello(Player* player, Creature* creature)
- {
- player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "I would like to place a bounty!", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
- player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, "Show me the bounty list!", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
- player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, "Nevermind..", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+3);
- if (player->IsGameMaster())
- player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, "Wipe Bounties", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+4);
- player->SEND_GOSSIP_MENU(1, creature->GetGUID());
- return true;
- }
- bool OnGossipSelect(Player* player, Creature* creature, uint32 /* sender */, uint32 actions)
- {
- player->PlayerTalkClass->ClearMenus();
- switch (actions)
- {
- case GOSSIP_ACTION_INFO_DEF+1:
- 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);
- 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);
- 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);
- 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);
- player->SEND_GOSSIP_MENU(1, creature->GetGUID());
- break;
- case GOSSIP_ACTION_INFO_DEF+2:
- {
- QueryResult result = CharacterDatabase.Query("SELECT * FROM bounties");
- if (!result)
- {
- player->CLOSE_GOSSIP_MENU();
- return false;
- }
- player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Bounties: ", GOSSIP_SENDER_MAIN, 1);
- do
- {
- Field* fields = result->Fetch();
- std::string option;
- QueryResult result2 = CharacterDatabase.PQuery("SELECT `name` FROM characters WHERE guid='%u' LIMIT 10", fields[0].GetUInt64());
- if (!result2)
- return false;
- Field* names = result2->Fetch();
- option = names[0].GetString();
- option += " ";
- option += fields[1].GetString();
- option += " gold";
- player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, option.c_str(), GOSSIP_SENDER_MAIN, 1);
- }while(result->NextRow());
- player->SEND_GOSSIP_MENU(1, creature->GetGUID());
- }break;
- case GOSSIP_ACTION_INFO_DEF+3:
- player->CLOSE_GOSSIP_MENU();
- break;
- case GOSSIP_ACTION_INFO_DEF+4:
- CharacterDatabase.Execute("TRUNCATE TABLE bounties");
- player->CLOSE_GOSSIP_MENU();
- break;
- }
- return true;
- }
- bool OnGossipSelectCode(Player* player, Creature* creature, uint32 /* sender */, uint32 actions, const char* code)
- {
- player->PlayerTalkClass->ClearMenus();
- if (islower(code[0]))
- toupper(code[0]);
- if (passChecks(player, code))
- {
- Player* hunted = sObjectAccessor->FindPlayerByName(code);
- switch (actions)
- {
- case GOSSIP_ACTION_INFO_DEF+5:
- {
- if (HasCurrency(player, BOUNTY_PRICE_1, 0))
- {
- CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u','20', '1')", hunted->GetGUID());
- BountyAlert(code, 1);
- FlagPlayer(code);
- player->CLOSE_GOSSIP_MENU();
- }
- }break;
- case GOSSIP_ACTION_INFO_DEF+6:
- {
- if (HasCurrency(player, BOUNTY_PRICE_2, 0))
- {
- CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '40', '2')", hunted->GetGUID());
- BountyAlert(code, 1);
- FlagPlayer(code);
- player->CLOSE_GOSSIP_MENU();
- }
- }break;
- case GOSSIP_ACTION_INFO_DEF+7:
- {
- if (HasCurrency(player, BOUNTY_PRICE_3, 0))
- {
- CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '100', '3')", hunted->GetGUID());
- BountyAlert(code, 1);
- FlagPlayer(code);
- player->CLOSE_GOSSIP_MENU();
- }
- }break;
- case GOSSIP_ACTION_INFO_DEF+8:
- {
- if (HasCurrency(player, BOUNTY_PRICE_4, 0))
- {
- CharacterDatabase.PExecute("INSERT INTO bounties VALUES('%u', '200', '4')", hunted->GetGUID());
- BountyAlert(code, 1);
- FlagPlayer(code);
- player->CLOSE_GOSSIP_MENU();
- }
- }break;
- }
- }
- else
- player->CLOSE_GOSSIP_MENU();
- return true;
- }
- bool HasCurrency(Player* player, uint32 required, int currency)
- {
- uint32 currentmoney = player->GetMoney();
- uint32 requiredmoney = (required * 10000);
- if(currentmoney < requiredmoney)
- {
- player->GetSession()->SendNotification("You don't have enough gold!");
- return false;
- }
- player->SetMoney(currentmoney - requiredmoney);
- return true;
- }
- bool passChecks(Player* player, const char* name)
- {
- Player* hunted = sObjectAccessor->FindPlayerByName(name);
- if(!hunted)
- {
- player->GetSession()->SendNotification("The player is offline or doesn't exist!");
- return false;
- }
- QueryResult result = CharacterDatabase.PQuery("SELECT * FROM bounties WHERE guid ='%u'", hunted->GetGUID());
- if(result)
- {
- player->GetSession()->SendNotification("This player already has a bounty on them!");
- return false;
- }
- if(player->GetGUID() == hunted->GetGUID())
- {
- player->GetSession()->SendNotification("You cannot set a bounty on yourself!");
- return false;
- }
- return true;
- }
- void FlagPlayer(const char* name)
- {
- Player* hunted = sObjectAccessor->FindPlayerByName(name);
- hunted->SetPvP(true);
- hunted->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);
- }
- };
- class BountyKills : public PlayerScript
- {
- public:
- BountyKills() : PlayerScript("BountyKills"){}
- void OnPVPKill(Player* killer, Player* victim)
- {
- if(killer->GetGUID() == victim->GetGUID())
- return;
- QueryResult result = CharacterDatabase.PQuery("SELECT * FROM bounties WHERE guid='%u'", victim->GetGUID());
- if(!result)
- return;
- Field* fields = result->Fetch();
- switch(fields[2].GetUInt64())
- {
- case 1:
- killer->SetMoney(killer->GetMoney() + (BOUNTY_PRICE_1 * 10000));
- break;
- case 2:
- killer->SetMoney(killer->GetMoney() + (BOUNTY_PRICE_2 * 10000));
- break;
- case 3:
- killer->SetMoney(killer->GetMoney() + (BOUNTY_PRICE_3 * 10000));
- break;
- case 4:
- killer->SetMoney(killer->GetMoney() + (BOUNTY_PRICE_4 * 10000));
- break;
- }
- CharacterDatabase.PExecute("DELETE FROM bounties WHERE guid='%u'", victim->GetGUID());
- BountyAlert(victim->GetName().c_str(), 2);
- }
- };
- void AddSC_bounty()
- {
- new BountyHunter();
- new BountyKills();
- }