Advertisement
Guest User

Untitled

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