Advertisement
Guest User

uScript - Bounty

a guest
Jul 22nd, 2019
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. minBounty = 1000; // Minimum Bounty That Can Be Placed
  2. bountyTextColor = "yellow";
  3. currencyName = "Gold";
  4.  
  5. // Creates The Necessary Table If It Does Not Already Exist
  6. event onLoad(){
  7. database.execute("CREATE TABLE IF NOT EXISTS bountylist(victimid VARCHAR(17) PRIMARY KEY,placerid VARCHAR(17) NOT NULL,bountyAmount INT DEFAULT 0,timePlaced DATETIME NOT NULL);");
  8. }
  9.  
  10. // Pays Player Who Killed Other Player With Bounty And Removes The Bounty
  11. event onPlayerDeath(player, cause, murdererId){
  12. if(murdererId == player.id){
  13. return;
  14. }
  15. murderer = toPlayer(murdererId);
  16. if(isPlayer(murderer) == false){
  17. return;
  18. }
  19. bounty = getBounty(player.id);
  20. if(bounty == false){
  21. return;
  22. }
  23. bountyAmount = toInt(bounty[2]);
  24. murderer.increaseBalance(bountyAmount);
  25. broadcast(str.format("[Bounty] {0} Has Killed {1} And Received Their {2} {3} Bounty!", murderer.name, player.name, bountyAmount, currencyName), bountyTextColor);
  26. database.execute(str.format("DELETE FROM bountylist WHERE victimid = '{0}';", player.id));
  27. }
  28.  
  29. // Command To Add A Bounty To A Player
  30. command bountyadd(arg1, arg2){
  31. permission = array("bounty", "bountyadd");
  32. execute(){
  33. if(isSet(arg1) == false or isSet(arg2) == false){
  34. player.message("[Bounty] Proper Usage: /bountyadd (player) (amount)", bountyTextColor);
  35. return;
  36. }
  37. target = toPlayer(arg1);
  38. if(isPlayer(target) == false){
  39. player.message("[Bounty] Could Not Find That Player!", bountyTextColor);
  40. return;
  41. }
  42. if(arg2 < minBounty or arg2 < 1){
  43. player.message(str.format("[Bounty] Your Bounty Must Be Be Greater Than {0} {1}!", minBounty, currencyName), bountyTextColor);
  44. return;
  45. }
  46. if(player.balance < arg2){
  47. player.message("[Bounty] You Can Not Afford A Bounty Of This Amount!", bountyTextColor);
  48. return;
  49. }
  50. bounty = getBounty(target.id);
  51. if(bounty != false){
  52. player.decreaseBalance(arg2);
  53. database.execute(str.format("UPDATE bountylist SET bountyAmount = bountyAmount + {0} WHERE victimid = '{1}';", arg2, target.id));
  54. bounty = getBounty(target.id);
  55. broadcast(str.format("[Bounty] {0} Has Increased The Bounty On {1} To {2} {3}!", player.name, target.name, bounty[2], currencyName), bountyTextColor);
  56. return;
  57. }
  58. player.decreaseBalance(arg2);
  59. broadcast(str.format("[Bounty] {0} Has Placed A Bounty Of {1} {2} On {3}!", player.name, arg2, currencyName, target.name), bountyTextColor);
  60. database.execute(str.format("INSERT INTO bountylist (victimid, placerid, bountyAmount, timePlaced) VALUES ('{0}', '{1}', {2}, CURRENT_TIMESTAMP);", target.id, player.id, arg2));
  61. }
  62. }
  63.  
  64. // Command To Remove A Bounty From A Player (Preferably For Staff Members)
  65. command bountyremove(arg){
  66. permission = array("bountyremove", "bountyadmin");
  67. execute(){
  68. if(isSet(arg) == false){
  69. player.message("[Bounty] Proper Usage: /bountyremove (player)", bountyTextColor);
  70. return;
  71. }
  72. target = toPlayer(arg);
  73. if(isPlayer(target) == false){
  74. player.message("[Bounty] Could Not Find That Player!", bountyTextColor);
  75. return;
  76. }
  77. bounty = getBounty(target.id);
  78. if(bounty == false){
  79. player.message(str.format("[Bounty] {0} Does Not Have A Bounty On Them!", target.name), bountyTextColor);
  80. return;
  81. }
  82. database.execute(str.format("DELETE FROM bountylist WHERE victimid = '{0}';", target.id));
  83. broadcast(str.format("[Bounty] {0} Has Forcefully Removed The Bounty On {1}", player.name, target.name), bountyTextColor);
  84. player.message("[Bounty] You Have Successfully Removed The Bounty On " + target.name + "!", bountyTextColor);
  85. }
  86. }
  87.  
  88. // Command To Pay Off Your Bounty
  89. command bountypay(){
  90. permission = array("bountypay", "bounty");
  91. execute(){
  92. bounty = getBounty(player.id);
  93. if(bounty == false){
  94. player.messge("[Bounty] You Do Not Have A Bounty On You!", bountyTextColor);
  95. return;
  96. }
  97. bountyAmount = toInt(bounty[2]);
  98. if(player.balance < bountyAmount){
  99. player.message(str.format("[Bounty] You Can Not Afford To Pay Off Your Bounty Of {0} {1}!", bountyAmount, currencyName));
  100. return;
  101. }
  102. player.decreaseBalance(bountyAmount);
  103. database.execute(str.format("DELETE FROM bountylist WHERE victimid = '{0}';", player.id));
  104. broadcast(str.format("[Bounty] {0} Has Payed Off The Bounty On Them!", player.name), bountyTextColor);
  105. }
  106. }
  107.  
  108. // Displays All People Online With Bounties
  109. command bountylist(){
  110. permission = array("bountylist", "bounty");
  111. execute(){
  112. output = "[Bounty] Bounties: ";
  113. bounties = database.execute("SELECT * FROM bountylist");
  114. foreach(bounty in bounties){
  115. if(isPlayer(toPlayer(bounty[0]))){
  116. output = str.format(output + toPlayer(bounty[0]).name + "(${0}) ", bounty[2]);
  117. }
  118. }
  119. player.message(output, bountyTextColor);
  120. }
  121. }
  122.  
  123. // Retrieves Bounty From Database
  124. function getBounty(victimID){
  125. bounty = database.execute(str.format("SELECT * FROM bountylist WHERE victimid = '{0}';", victimID));
  126. if(bounty.count == 0){
  127. return false;
  128. }
  129. return bounty[0];
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement