Advertisement
Xyberviri

BountyBoard.js

Mar 29th, 2015
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var BountyBoard = {
  2.   Title: "Bounty Board",
  3.   Author: "Killparadise",
  4.   Version: V(1, 1, 2),
  5.   Init: function() {
  6.     this.registerPermissions();
  7.     this.getData();
  8.     global = importNamespace("");
  9.   },
  10.  
  11.   OnServerInitialized: function() {
  12.     this.msgs = this.Config.Messages;
  13.     this.prefix = this.Config.Prefix;
  14.     friendsAPI = plugins.Find('0friendsAPI');
  15.     clansOn = plugins.Find('Clans');
  16.     if (this.Config.Settings.useEcon) {
  17.       economy = plugins.Find("00-Economics");
  18.       econAPI = economy.Call("GetEconomyAPI");
  19.     }
  20.     this.updateConfig();
  21.     command.AddChatCommand("bty", this.Plugin, "cmdBounty");
  22.     //globalTimer = timer.Repeat(this.Config.TargetSettings.degradeInterval, 0, function() {
  23.     //this.degradeModifier();
  24.     //}, this.Plugin);
  25.   },
  26.  
  27.   // Unload: function() {
  28.   //   globalTimer.Destroy();
  29.   // },
  30.  
  31.   updateConfig: function() {
  32.     if (this.Config.Version !== "1.3") {
  33.       print("[BountyBoard] Updating Config, to latest version.");
  34.       this.LoadDefaultConfig();
  35.       this.SaveConfig();
  36.     } else {
  37.       return false;
  38.     }
  39.   },
  40.  
  41.   LoadDefaultConfig: function() {
  42.     this.Config.authLevel = 2;
  43.     this.Config.Version = "1.3";
  44.     this.Config.Settings = {
  45.       "autoBounties": true,
  46.       "currency": "Dollars",
  47.       "maxBounty": 100000,
  48.       "staffCollect": false,
  49.       "useEcon": false,
  50.       "antiFriend": true
  51.     };
  52.  
  53.     this.Config.TargetSettings = {
  54.       "timer": 3600,
  55.       "modifier": 20,
  56.       "degrade": 3,
  57.       "degradeInterval": 720,
  58.       "enableTarget": true
  59.     };
  60.  
  61.     this.Config.Permissions = {
  62.       "reset": "canReset"
  63.     };
  64.  
  65.     this.Config.Prefix = "BountyBoard";
  66.  
  67.     this.Config.Messages = {
  68.       "curBounty": "The Current Bounty on your head is: ",
  69.       "invSyn": "Syntax Invalid, Please try again. {cmd}",
  70.       "noBty": "Target has no Bounty!",
  71.       "setTar": "Target set. Happy Hunting.",
  72.       "setTrgWarn": " Made you his target! Watch out!",
  73.       "curTar": "Your current target is: ",
  74.       "offline": "That Player is currently offline.",
  75.       "btyClaim": "<color=lime>plyrName</color> has taken the bounty of <color=green>btyAmt</color> from <color=red>deadPlyr</color>!",
  76.       "staff": "Sorry, Staff cannot collect Bounties from slain players.",
  77.       "btyPlaced": "Someone placed a <color=green>{bty}</color> bounty on you!",
  78.       "notEnough": "Not Enough <color=red>{RssName}</color>",
  79.       "overMax": "You cannot exceed the max bounty of <color=red>{maxBty}</color>",
  80.       "notFound": "Item Not Found.",
  81.       "currBty": "The Current Bounty on your head is: ",
  82.       "resetData": "BountyBoard Data Reset",
  83.       "btySet": "<color=green>{bty}</color> bounty has been set!",
  84.       "negBty": "You cannot set a negative bounty!",
  85.       "noPerms": "You do not have permission to use this command.",
  86.       "econOn": "Cannot use item types, Economy is turned On",
  87.       "disabled": "The {function} feature is currently disabled.",
  88.       "boardcastBty": "Somebody has put a bounty of <color=green>rss</color> on <color=lime>plyr</color>'s head! Happy hunting!"
  89.     };
  90.  
  91.     this.Config.Help = [
  92.  
  93.       "/bty - Check the current bounty on your head",
  94.       "/bty add playername amt itemname - Add a bounty onto a targeted player.",
  95.       "/bty board - shows the Bounty Board of everyone who has a bounty.",
  96.       "/bty target playername - sets a entered player as a target to the user."
  97.     ];
  98.     this.Config.AdminHelp = [
  99.  
  100.       "/bty reset - resets all of the bounty board data"
  101.     ];
  102.   },
  103.  
  104.   OnPlayerInit: function(player) {
  105.     this.checkPlayerData(player);
  106.   },
  107.  
  108.   //----------------------------------------
  109.   //       Register Permissions
  110.   //----------------------------------------
  111.  
  112.   registerPermissions: function() {
  113.     var p = this.Config.Permissions;
  114.     for (var perm in p) {
  115.       if (!permission.PermissionExists(p[perm])) {
  116.         permission.RegisterPermission(p[perm], this.Plugin);
  117.       }
  118.     }
  119.   },
  120.  
  121.   //----------------------------------------
  122.   //         Permissions Check
  123.   //----------------------------------------
  124.  
  125.   hasPermission: function(player, perm) {
  126.     var steamID = rust.UserIDFromPlayer(player);
  127.     if (player.net.connection.authLevel === 2) {
  128.       return true;
  129.     }
  130.  
  131.     if (permission.UserHasPermission(steamID, perm)) {
  132.       return true;
  133.     }
  134.  
  135.     return false;
  136.   },
  137.  
  138.   //----------------------------------------
  139.   //          Finding Player Info
  140.   //----------------------------------------
  141.   findPlayerByName: function(playerName) {
  142.     try {
  143.       var found = [],
  144.         foundID;
  145.       playerName = playerName.toLowerCase();
  146.       var itPlayerList = global.BasePlayer.activePlayerList.GetEnumerator();
  147.       while (itPlayerList.MoveNext()) {
  148.  
  149.         var displayName = itPlayerList.Current.displayName.toLowerCase();
  150.  
  151.         if (displayName.search(playerName) > -1) {
  152.           print("found match " + displayName);
  153.           found.push(itPlayerList.Current);
  154.         }
  155.  
  156.         if (playerName.length === 17) {
  157.           if (rust.UserIDFromPlayer(displayName).search(playerName)) {
  158.             found.push(itPlayerList.Current);
  159.           }
  160.         }
  161.       }
  162.  
  163.       if (found.length) {
  164.         foundID = rust.UserIDFromPlayer(found[0]);
  165.         found.push(foundID);
  166.         return found;
  167.       } else {
  168.         return false;
  169.       }
  170.     } catch (e) {
  171.       print(e.message.toString());
  172.     }
  173.   },
  174.  
  175.   findPlayerByID: function(playerid) {
  176.     var global = importNamespace("");
  177.     var targetPlayer = global.BasePlayer.Find(playerid);
  178.     if (targetPlayer) {
  179.       return targetPlayer;
  180.     } else {
  181.       return false;
  182.     }
  183.   },
  184.  
  185.   //----------------------------------------
  186.   //          Data Handling
  187.   //----------------------------------------
  188.   getData: function() {
  189.     BountyData = data.GetData('Bounty');
  190.     BountyData = BountyData || {};
  191.     BountyData.PlayerData = BountyData.PlayerData || {};
  192.     BountyData.Board = BountyData.Board || {};
  193.     BountyData.TimerData = BountyData.TimerData || {};
  194.   },
  195.  
  196.   saveData: function() {
  197.     data.SaveData('Bounty');
  198.   },
  199.  
  200.   checkPlayerData: function(player) {
  201.     var steamID = rust.UserIDFromPlayer(player);
  202.     var authLvl = player.net.connection.authLevel;
  203.     BountyData.PlayerData[steamID] = BountyData.PlayerData[steamID] || {};
  204.     BountyData.PlayerData[steamID].Target = BountyData.PlayerData[steamID].Target || "";
  205.     BountyData.PlayerData[steamID].isTarget = BountyData.PlayerData[steamID].isTarget || false;
  206.     BountyData.PlayerData[steamID].Bounty = BountyData.PlayerData[steamID].Bounty || [];
  207.     BountyData.PlayerData[steamID].BountyType = BountyData.PlayerData[steamID].BountyType || [];
  208.     BountyData.PlayerData[steamID].isStaff = BountyData.PlayerData[steamID].isStaff || (authLvl > 0) || false;
  209.     this.saveData();
  210.   },
  211.  
  212.   //----------------------------------------
  213.   //          Command Handling
  214.   //----------------------------------------
  215.   cmdBounty: function(player, cmd, args) {
  216.     try {
  217.       var steamID = rust.UserIDFromPlayer(player);
  218.       var authLvl = player.net.connection.authLevel;
  219.       var perms = this.Config.Permissions;
  220.       switch (args[0]) {
  221.         case "add":
  222.           this.addBounty(player, cmd, args);
  223.           break;
  224.         case "board":
  225.           this.checkBoard(player, cmd, args);
  226.           break;
  227.         case "help":
  228.           this.BtyHelp(player);
  229.           break;
  230.         case "reset":
  231.           if (this.hasPermission(player, perms.canReset)) {
  232.             this.resetData(player, cmd, args);
  233.           } else if (!this.hasPermission(player, perms.canReset)) {
  234.             rust.SendChatMessage(player, this.prefix, this.msgs.noPerms, "0");
  235.             return false;
  236.           } else {
  237.             rust.SendChatMessage(player, this.prefix, this.msgs.invSyn.replace("{cmd}", "/bty arg"), "0");
  238.             return false;
  239.           }
  240.           break;
  241.         default:
  242.           if (BountyData.PlayerData[steamID] === undefined) {
  243.             print("Player Data not Found for " + steamID + " Attempting to build");
  244.             this.checkPlayerData(player);
  245.           } else {
  246.             if (BountyData.PlayerData[steamID].Bounty.length > 0) {
  247.               rust.SendChatMessage(player, this.prefix, this.msgs.currBty + " " + "<color=green>" + BountyData.PlayerData[steamID].Bounty + "</color>", "0");
  248.             } else {
  249.               rust.SendChatMessage(player, this.prefix, this.msgs.currBty + " " + "<color=green>" + "0" + "</color>", "0");
  250.             }
  251.           }
  252.           break;
  253.       }
  254.     } catch (e) {
  255.       print(e.message.toString());
  256.     }
  257.   },
  258.  
  259.   resetData: function(player, cmd, args) {
  260.     try {
  261.       delete BountyData.PlayerData;
  262.       delete BountyData.Board;
  263.       delete BountyData.TimerData;
  264.       this.saveData();
  265.       this.getData();
  266.       rust.SendChatMessage(player, this.prefix, this.msgs.resetData, "0");
  267.     } catch (e) {
  268.       print(e.message.toString());
  269.     }
  270.   },
  271.  
  272.   setTarget: function(player, cmd, args) {
  273.     var pName = this.findPlayerByName(args[1]);
  274.     var steamID = rust.UserIDFromPlayer(player);
  275.     if (args.length === 1) {
  276.       rust.SendChatMessage(player, this.prefix, this.msgs.curTar, "0");
  277.     } else {
  278.       rust.SendChatMessage(player, this.prefix, this.msgs.invSyn.replace("{cmd}", "/bty target playername"), "0");
  279.     }
  280.     print(pName[0].displayName);
  281.     if (pName[0].displayName !== player.displayName && BountyData.PlayerData[pName[1]].Bounty.length > 0 && pName[0].IsConnected()) {
  282.       BountyData.PlayerData[steamID].Target = pName[0].displayName;
  283.       BountyData.PlayerData[pName[1]].isTarget = true;
  284.       this.buildTimer(pName[0]);
  285.       rust.SendChatMessage(player, this.prefix, this.msgs.setTar, "0");
  286.       rust.SendChatMessage(pName[0], this.prefix, player.displayName + this.msgs.setTrgWarn, "0");
  287.     } else if (!pName[0].IsConnected()) {
  288.       rust.SendChatMessage(player, this.prefix, this.msgs.offline, "0");
  289.     } else {
  290.       rust.SendChatMessage(player, this.prefix, this.msgs.noBty, "0");
  291.     }
  292.   },
  293.  
  294.   //---------------------------------------
  295.   //                    Timer Handler
  296.   //        Handles all timer related items
  297.   //---------------------------------------
  298.   handleTimer: function(player, status) {
  299.     var steamID = rust.UserIDFromPlayer(player);
  300.     if (status === "logout") {
  301.       BountyData.TimerData[steamID].paused = BountyData.TimerData[steamID].modifiedTime - System.DateTime.Now.Second;
  302.       BountyData.TimerData[steamID].timer.Destroy();
  303.     } else if (status === "login") {
  304.       BountyData.TimerData[steamID].timer = timer.Once(BountyData.TimerData[steamID].paused, function() {
  305.         this.deleteTimer(BountyData.TimerData[steamID].timer, steamID);
  306.       });
  307.       BountyData.TimerData[steamID].paused = "";
  308.     }
  309.     this.saveData();
  310.   },
  311.  
  312.   buildTimer: function(player) {
  313.     var steamID = rust.UserIDFromPlayer(player);
  314.     if (BountyData.PlayerData[steamID].isTarget) {
  315.       BountyData.TimerData[steamID].name = player.displayName;
  316.       BountyData.TimerData[steamID].modifier = this.Config.TargetSettings.modifier;
  317.       BountyData.TimerData[steamID].startTime = System.DateTime.Now.Second;
  318.       BountyData.TimerData[steamID].modifiedTime = System.DateTime.Now.Second + this.Config.timer;
  319.       BountyData.TimerData[steamID].timer = timer.Once(this.Config.TargetSettings.timer, function() {
  320.         this.deleteTimer(BountyData.TimerData[steamID].timer, steamID);
  321.       });
  322.     } else {
  323.       return false;
  324.     }
  325.   },
  326.  
  327.   deleteTimer: function(timer, steamID) {
  328.  
  329.     if (timer) {
  330.       BountyData.PlayerData[steamID].isTarget = false;
  331.       timer.Destroy();
  332.     }
  333.   },
  334.  
  335.   degradeModifier: function() {
  336.     var grabTime = System.DateTime.Now.Second;
  337.     for (var id in BountyData.TimerData) {
  338.       var curTime = BountyData.TimerData[id].modifiedTime - System.DateTime.Now.Second;
  339.       var lengthOfRun = grabTime - BountyData.TimerData[steamID].startTime;
  340.       if (lengthOfRun >= 300) {
  341.         BountyData.TimerData[id].modifier -= this.Config.TargetSettings.degrade;
  342.       }
  343.     }
  344.   },
  345.  
  346.   //----------------------------------------
  347.   //          Bounty Handler
  348.   //        Handles adding bounties and
  349.   //        keeps track of bounties
  350.   //----------------------------------------
  351.   addBounty: function(player, cmd, args) {
  352.     try {
  353.       var steamID = rust.UserIDFromPlayer(player);
  354.       var authLvl = player.net.connection.authLevel;
  355.       var main = player.inventory.containerMain;
  356.       var mainList = main.itemList.GetEnumerator();
  357.       var targetPlayer = this.findPlayerByName(args[1]);
  358.       var argObj;
  359.       if (args.length === 4) {
  360.         argObj = {
  361.           "plyrName": args[1],
  362.           "amt": Number(args[2]),
  363.           "itemName": args[3]
  364.         };
  365.  
  366.         if (!BountyData.PlayerData[targetPlayer[1]]) this.checkPlayerData(targetPlayer[0]);
  367.         while (mainList.MoveNext()) {
  368.           name = mainList.Current.info.shortname;
  369.           amount = mainList.Current.amount;
  370.           condition = mainList.Current.condition;
  371.           if (name === argObj.itemName && argObj.amt <= amount && argObj.amt <= this.Config.Settings.maxBounty && argObj.amt > 0) {
  372.             break;
  373.           }
  374.         }
  375.       } else if (args.length === 3) {
  376.         player.ChatMessage("BountyBoard currently does not support Economics, please use item bounties for now.");
  377.         return false;
  378.         // argObj = {
  379.         //   "plyrName": args[1],
  380.         //   "amt": Number(args[2]),
  381.         //   "itemName": this.Config.Settings.currency
  382.         // };
  383.         // userData = economy.Call("API:GetUserDataFromPlayer", player);
  384.         // amount = userData[1];
  385.         // econAPI.Call("Withdraw", argObj.amt);
  386.         // print("Withdraw Money");
  387.       } else {
  388.         rust.SendChatMessage(player, this.prefix, this.msgs.invSyn.replace("{cmd}", "/bty add itemamt itemname", "0"));
  389.       }
  390.  
  391.       if (argObj.amt > amount) {
  392.         print(argObj.amt);
  393.         rust.SendChatMessage(player, this.prefix, this.msgs.notEnough.replace("{RssName}", argObj.itemName), "0");
  394.         return false;
  395.       } else if (argObj.amt <= 0) {
  396.         rust.SendChatMessage(player, this.prefix, this.msgs.negBty, "0");
  397.         return false;
  398.       } else if (argObj.amt > this.Config.Settings.maxBounty) {
  399.         rust.SendChatMessage(player, this.prefix, this.msgs.overMax.replace("{maxBty}", this.Config.Settings.maxBounty), "0");
  400.         return false;
  401.       } else if (args.length === 4 && name !== argObj.itemName) {
  402.         rust.SendChatMessage(player, this.prefix, this.msgs.notFound, "0");
  403.         return false;
  404.       }
  405.       if (args.length === 4) {
  406.         var definition = global.ItemManager.FindItemDefinition(name);
  407.         main.Take(null, Number(definition.itemid), argObj.amt);
  408.       }
  409.       if (this.checkForDupes(targetPlayer[1], argObj.itemName, argObj.amt)) {} else {
  410.         BountyData.PlayerData[targetPlayer[1]].Bounty.push(argObj.amt + " " + argObj.itemName);
  411.         BountyData.PlayerData[targetPlayer[1]].BountyType.push(argObj.itemName);
  412.       }
  413.       var rplObj = {
  414.         "rss": argObj.amt + " " + argObj.itemName,
  415.         "plyr": targetPlayer[0].displayName
  416.       };
  417.       rust.SendChatMessage(targetPlayer[0], this.prefix, this.msgs.btyPlaced.replace("{bty}", argObj.amt + " " + argObj.itemName), "0");
  418.       rust.SendChatMessage(player, this.prefix, this.msgs.btySet.replace("{bty}", argObj.amt + " " + argObj.itemName), "0");
  419.       rust.BroadcastChat(this.prefix, this.msgs.boardcastBty.replace(/rss|plyr/gi, function(matched) {
  420.         return rplObj[matched];
  421.       }), "0");
  422.       this.saveData();
  423.       this.updateBoard(targetPlayer[1], false, argObj.amt, argObj.itemName);
  424.     } catch (e) {
  425.       print(e.message.toString());
  426.     }
  427.   },
  428.  
  429.   //----------------------------------------
  430.   //          Board Handling
  431.   //        Handle Board updates, dupes, etc
  432.   //----------------------------------------
  433.   updateBoard: function(targetID, claimed, amount, itemName) {
  434.     //TODO: update the bounty board with new bounties and claimed bounties.
  435.     var getPlayer = this.findPlayerByID(targetID);
  436.  
  437.     if (claimed && itemName === null && amount === 0) {
  438.       delete BountyData.Board[targetID];
  439.       BountyData.PlayerData[targetID].Bounty = [];
  440.       BountyData.PlayerData[targetID].BountyType = [];
  441.       return this.saveData();
  442.     }
  443.  
  444.     if (BountyData.Board[targetID] === undefined) {
  445.       BountyData.Board[targetID] = {};
  446.       BountyData.Board[targetID].Name = getPlayer.displayName;
  447.       BountyData.Board[targetID].Amount = [amount + " " + itemName];
  448.       BountyData.Board[targetID].ItemType = [itemName];
  449.     } else if (claimed === false && BountyData.Board[targetID] !== undefined) {
  450.       BountyData.Board[targetID].Amount = BountyData.PlayerData[targetID].Bounty;
  451.       BountyData.Board[targetID].ItemType = BountyData.PlayerData[targetID].BountyType;
  452.     }
  453.     this.saveData();
  454.   },
  455.  
  456.   checkForDupes: function(targetID, itemName, amt) {
  457.     try {
  458.       var boardData = BountyData.Board[targetID];
  459.       var playerData = BountyData.PlayerData[targetID];
  460.       var i = 0;
  461.       if (boardData === undefined) {
  462.         return false;
  463.       }
  464.       for (i; i < boardData.Amount.length; i++) {
  465.         var itemTypeName = boardData.Amount[i].split(" ").pop();
  466.         if (itemName === itemTypeName) {
  467.           var storedAmt = boardData.Amount[i].split(" ").shift();
  468.           var newAmt = Number(storedAmt) + Number(amt);
  469.           boardData.Amount[i] = newAmt + " " + itemName;
  470.           boardData.ItemType[i] = itemName;
  471.           playerData.Bounty[i] = newAmt + " " + itemName;
  472.           playerData.BountyType[i] = itemName;
  473.           return true;
  474.         }
  475.       }
  476.       return false;
  477.     } catch (e) {
  478.       print(e.message.toString());
  479.     }
  480.   },
  481.  
  482.   checkBoard: function(player, cmd, args) {
  483.     rust.SendChatMessage(player, "", "<color=orange>------Bounty Board------</color>", "0");
  484.     for (var key in BountyData.Board) {
  485.       rust.SendChatMessage(player, "", "<color=red>" + BountyData.Board[key].Name + ": " + BountyData.Board[key].Amount + "</color>", "0");
  486.     }
  487.     rust.SendChatMessage(player, "", "<color=orange>------Happy Hunting------</color>", "0");
  488.   },
  489.  
  490.   //----------------------------------------
  491.   //          Bounty Handling
  492.   //        Handle Claims, and Item Giving
  493.   //----------------------------------------
  494.   claimBounty: function(victimID, attackerID) {
  495.     var amount = BountyData.Board[victimID].Amount,
  496.       item = BountyData.Board[victimID].ItemType,
  497.       claimed = false;
  498.  
  499.     var getPlayer = this.findPlayerByID(attackerID);
  500.     print(getPlayer.displayName);
  501.     var i = 0;
  502.     for (i; i < amount.length; i++) {
  503.       this.giveItem(getPlayer, victimID, item[i], amount[i].split(" ").shift());
  504.     }
  505.     claimed = true;
  506.     this.updateBoard(victimID, claimed, 0, null);
  507.   },
  508.  
  509.   giveItem: function(player, victimID, itemName, amount) {
  510.     try {
  511.       if (BountyData.PlayerData[victimID].isTarget) {
  512.         BountyData.PlayerData[victimID].isTarget = false;
  513.         BountyData.PlayerData[victimID].timer.Destroy();
  514.       }
  515.  
  516.       itemName = itemName.toLowerCase();
  517.       if (itemName === this.Config.Settings.currency) {
  518.         var econData = econAPI.Call("GetUserDataFromPlayer", player);
  519.         econData.Call("Deposit", amount);
  520.       } else if (itemName !== this.Config.Settings.currency) {
  521.       var definition = global.ItemManager.FindItemDefinition(itemName);
  522.       if (definition === null) return print("Unable to Find an Item for Bounty.");
  523.       print("Giving Item: " + definition.itemid);
  524.       player.inventory.GiveItem(global.ItemManager.CreateByItemID(Number(definition.itemid), Number(amount), false), player.inventory.containerMain);
  525.     }
  526.   } catch (e) {
  527.       print(e.message.toString());
  528.     }
  529.     this.saveData();
  530.  
  531.   },
  532.  
  533.   //----------------------------------------
  534.   //          Handle Friends
  535.   //    Check if players are friends/clan mates
  536.   //----------------------------------------
  537.   checkForFriends: function(victimID, attackerID) {
  538.     //check for friends
  539.     try {
  540.       if (this.Config.Settings.antiFriend) {
  541.         if (friendsAPI && friendsAPI.Call("HasFriend", attackerID, victimID)) {
  542.           return true;
  543.         } else if (clansOn && !clansOn.Call("HasFriend", attackerID, victimID)) {
  544.           attackerClan = clansOn.Call("FindClanByUser", attackerID);
  545.           victimClan = clansOn.Call("FindClanByUser", victimID);
  546.           if (attackerClan === victimClan) {
  547.             return true;
  548.           } else {
  549.             return false;
  550.           }
  551.         } else {
  552.           return true;
  553.         }
  554.       }
  555.       return false;
  556.     } catch (e) {
  557.       print(e.message.toString());
  558.     }
  559.   },
  560.  
  561.   //----------------------------------------
  562.   //          Death Handling
  563.   //        Checks for bounties, data, etc.
  564.   //----------------------------------------
  565.   OnEntityDeath: function(entity, hitinfo) {
  566.     try {
  567.       var victim = entity;
  568.       var attacker = hitinfo.Initiator;
  569.  
  570.       if (victim.ToPlayer() && attacker.ToPlayer() && victim.displayName !== attacker.displayName) {
  571.         var victimID = rust.UserIDFromPlayer(victim),
  572.           attackerID = rust.UserIDFromPlayer(attacker);
  573.         if (this.checkForFriends(victimID, attackerID)) return false;
  574.         if (!BountyData.PlayerData[victimID] && !victim.IsConnected()) {
  575.           return false;
  576.         } else if (!BountyData.PlayerData[victimID] && victim.IsConnected()) {
  577.           print("Data File not found for " + victim.displayName + ", attempting build now...");
  578.           this.checkPlayerData(victim);
  579.         } else if (!BountyData.PlayerData[attackerID]) {
  580.           print("Data File not found for " + attacker.displayName + ", attempting build now...");
  581.           this.checkPlayerData(attacker);
  582.         }
  583.  
  584.  
  585.         if (BountyData.PlayerData[victimID].Bounty.length > 0 && victim.displayName !== attacker.displayName) {
  586.           if (BountyData.PlayerData[attackerID].isStaff && !this.Config.Settings.staffCollect) {
  587.             rust.SendChatMessage(attacker, this.prefix, this.msgs.staff, "0");
  588.             return false;
  589.           }
  590.           var rpObj = {
  591.             plyrName: attacker.displayName,
  592.             btyAmt: BountyData.PlayerData[victimID].Bounty,
  593.             deadPlyr: victim.displayName
  594.           };
  595.           rust.BroadcastChat(this.prefix, this.msgs.btyClaim.replace(/plyrName|btyAmt|deadPlyr/g, function(matched) {
  596.             return rpObj[matched];
  597.           }), "0");
  598.           this.claimBounty(victimID, attackerID);
  599.  
  600.         } else if (victim.ToPlayer() && victim.displayName === attacker.displayName) {
  601.           return false;
  602.         }
  603.       }
  604.     } catch (e) {
  605.       print(e.message.toString());
  606.     }
  607.   },
  608.  
  609.   BtyHelp: function(player) {
  610.     rust.SendChatMessage(player, null, "--------------BountyBoard Commands------------", "0");
  611.     var authLvl = player.net.connection.authLevel;
  612.     for (var i = 0; i < this.Config.Help.length; i++) {
  613.       rust.SendChatMessage(player, null, this.Config.Help[i], "0");
  614.     }
  615.     if (authLvl >= 2) {
  616.       rust.SendChatMessage(player, null, "<color=orange>--------------Admin Commands------------</color>", "0");
  617.       for (var j = 0; j < this.Config.AdminHelp.length; j++) {
  618.         rust.SendChatMessage(player, null, this.Config.AdminHelp[j], "0");
  619.       }
  620.     }
  621.   }
  622. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement