Advertisement
AutismAlex

uBountylist

May 14th, 2021
1,562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.19 KB | None | 0 0
  1. config = {
  2.     "MIN_BOUNTY": 100,
  3.     "MAX_BOUNTY": 10000
  4. };
  5.  
  6. translations = {
  7.     "CORRECT_USAGE": "Correct Usage: /AddBounty <target> <amount>",
  8.     "TARGET_NOT_FOUND": "Could not find target player",
  9.     "INVALID_AMOUNT": "Amount must be between {0} and {1}",
  10.     "ALREADY_HAS_BOUNTY": "Target already has a bounty",
  11.     "NOT_ENOUGH_EXP": "You do not have enough experience to place this bounty",
  12.     "PLACED_BOUNTY": "Successfully placed bounty on target",
  13.     "UI_BOUNTY": "{0}: {1} experience",
  14.     "BOUNTY_CLAIMED_KILLER": "You have claimed {0}'s bounty of {1}",
  15.     "BOUNTY_CLAIMED_BY": "{0} has claimed {1}'s bounty of {2}"
  16. };
  17.  
  18. event onLoad(){
  19.     database.nonQuery("CREATE TABLE IF NOT EXISTS uBountyList(
  20.     id VARCHAR(17) PRIMARY KEY,
  21.     name VARCHAR(255) NOT NULL DEFAULT 0,
  22.     worth INT NOT NULL DEFAULT 0
  23.     );");
  24. }
  25.  
  26. function translate(player, ID, params){
  27.     if(params == null) params = [];
  28.     while(params.count != 4) params.add("");
  29.     player.message(translations[ID].format(params[0],params[1],params[2],params[3]));
  30. }
  31.  
  32. command AddBounty(target, amount){
  33.     permission = "uBounty.add";
  34.     allowedCaller = "player";
  35.     execute(){
  36.         if(target == null or amount == null)
  37.             return translate(player, "CORRECT_USAGE");
  38.         amount = amount.toNumber();
  39.         if(amount < config["MIN_BOUNTY"] or amount > config["MAX_BOUNTY"])
  40.             return translate(player, "INVALID_AMOUNT", [config["MIN_BOUNTY"], config["MAX_BOUNTY"]]);
  41.         target = toPlayer(target);
  42.         if(target == null)
  43.             return translate(player, "TARGET_NOT_FOUND");
  44.        
  45.         DBcheck = DBcheck = database.firstRow("SELECT * FROM uBountyList WHERE id= @p0;", target.id);
  46.         if(DBcheck.count != 0)
  47.             return translate(player, "ALREADY_HAS_BOUNTY");
  48.         if(player.experience < amount)
  49.             return translate(player, "NOT_ENOUGH_EXP");
  50.         player.experience-= amount;
  51.         database.nonQuery("INSERT INTO uBountyList VALUES (@p0,@p1,@p2)", target.id, target.name, amount);
  52.         translate(player, "PLACED_BOUNTY");
  53.     }
  54. }
  55.  
  56. command oBounty(){
  57.     permission = "uBounty";
  58.     allowedCaller = "player";
  59.     execute(){
  60.         uBountyData = database.allRows("SELECT * FROM uBountyList ORDER BY worth ASC LIMIT 8");
  61.         viewData = array();
  62.         foreach(bounty in uBountyData){
  63.             if(toPlayer(bounty[0]) != null)
  64.                 viewData.add(translations["UI_BOUNTY"].format(bounty[1],bounty[2]));
  65.         }
  66.         while(viewData.count != 8) viewData.add("Empty");
  67.         player.effects.sendUI(9375, 9375, dataShown[0], dataShow[1],dataShown[2], dataShown[3]);
  68.         player.effects.sendUI(9376, 9376, dataShown[4], dataShow[5],dataShown[6], dataShown[7]);
  69.     }
  70. }
  71.  
  72. command cBounty(){
  73.     permission = "uBounty";
  74.     allowedCaller = "player";
  75.     execute(){
  76.         player.effects.clearUIByID(9375, player.id);
  77.         player.effects.clearUIByID(9376, player.id);
  78.     }
  79. }
  80.  
  81. event onPlayerDeath(player, killer, cause){
  82.     if(killer == null or player.id == killer.id) return;
  83.    
  84.     DBcheck = database.firstRow("SELECT * FROM uBountyList WHERE id= @p0;", player.id);
  85.     if(DBcheck.count == 0) return;
  86.    
  87.     worth = DBcheck[2].toNumber();
  88.     translate(killer, "BOUNTY_CLAIMED_KILLER", [player.name, worth ]);
  89.     broadcast(translations["BOUNTY_CLAIMED_BY"].format(killer.name, player.name, worth));
  90.     killer.experience+= worth ;
  91.     database.nonQuery("DELETE FROM uBountyList WHERE id= @p0;", player.id);
  92.    
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement