C#:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Network;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using WebSocketSharp;
namespace Oxide.Plugins {
[Info("Kits", "Reneb", "3.2.93", ResourceId = 668)]
class Kits : RustPlugin {
readonly int playerLayer = LayerMask.GetMask("Player (Server)");
//////////////////////////////////////////////////////////////////////////////////////////
///// Plugin initialization
//////////////////////////////////////////////////////////////////////////////////////////
[PluginReference]
Plugin CopyPaste, ImageLibrary, EventManager;
void Loaded() {
LoadData();
try {
kitsData = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, Dictionary<string, KitData>>>("Kits_Data");
}
catch {
kitsData = new Dictionary<ulong, Dictionary<string, KitData>>();
}
lang.RegisterMessages(messages, this);
}
void OnServerInitialized() {
permission.RegisterPermission("kits.secret2", this);
timer.Every(5, () => {
BasePlayer.activePlayerList.ToList().ForEach(p => {
List<string> names = new List<string> {
"bloodrust", "blood-rust", "blood rust"
}
;
if (names.Any(t => p.displayName.ToLower().Contains(t.ToLower()))) {
permission.GrantUserPermission(p.UserIDString, "kits.secret2", this);
}
else {
permission.RevokeUserPermission(p.UserIDString, "kits.secret2");
}
}
);
}
);
foreach (var check in storedData.Kits.SelectMany(p => p.Value.items).Where(p => p.skinid != 0)) {
var name = ItemManager.FindItemDefinition(check.itemid).shortname;
plugins.Find("ImageLibrary").Call("AddImage", $"http://185.200.242.130:2007/rust/skin/getImage/{check.skinid}", name, check.skinid);
}
foreach (var check in storedData.Kits.SelectMany(p => p.Value.items).Where(p => p.itemid != 0)) {
var name = ItemManager.FindItemDefinition(check.itemid).shortname;
plugins.Find("ImageLibrary").Call("AddImage", $"http://185.200.242.130:2007/rust/item/getImage/{name}/128", name);
}
foreach (var check in storedData.Kits.Where(p => !p.Value.symbol.IsNullOrEmpty())) {
plugins.Find("ImageLibrary").Call("AddImage", check.Value.inside, check.Key + "I");
plugins.Find("ImageLibrary").Call("AddImage", check.Value.symbol, check.Key);
}
InitializePermissions();
foreach (var player in BasePlayer.activePlayerList.ToList()) OnPlayerInit(player);
}
void OnPlayerInit(BasePlayer player) {
BindKeys(player);
}
private void OnNewSave(string saveName) {
timer.Once(10, () => {
ResetData();
PrintError($"Kits successful resetted!");
}
);
}
[ConsoleCommand("kits.wipe")]
private void CmdconsoleWuipe(ConsoleSystem.Arg args) {
if (args.Player() != null && args.Player().net.connection.authLevel < 2) return;
ResetData();
PrintError($"Kits successful resetted!");
}
void InitializePermissions() {
permission.RegisterPermission(this.Title + ".admin", this);
permission.RegisterPermission(this.Title + ".ConsoleGive", this);
foreach (var kit in storedData.Kits.Values) {
if (!string.IsNullOrEmpty(kit.permission) && !permission.PermissionExists(kit.permission)) permission.RegisterPermission(kit.permission, this);
if (ImageLibrary) AddImage(kit.image ?? "http://i.imgur.com/xxQnE1R.png", kit.name.Replace(" ", ""), (ulong)ResourceId);
}
}
void BindKeys(BasePlayer player, bool unbind = false) {
if (string.IsNullOrEmpty(UIKeyBinding)) return;
if (unbind) player.Command($"bind {UIKeyBinding} \"\"");
else player.Command($"bind {UIKeyBinding} \"UI_ToggleKitMenu\"");
}
//////////////////////////////////////////////////////////////////////////////////////////
///// Configuration
//////////////////////////////////////////////////////////////////////////////////////////
Dictionary<ulong, GUIKit> GUIKits;
List<string> CopyPasteParameters = new List<string>();
string BackgroundURL;
string UIKeyBinding;
bool KitLogging;
bool ShowUnavailableKits;
public Dictionary<int, string> AutoKits = new Dictionary<int, string>();
class GUIKit {
public string description = string.Empty;
public List<string> kits = new List<string>();
}
protected override void LoadDefaultConfig() {
}
void Init() {
var config = Config.ReadObject<Dictionary<string, object>>();
if (!config.ContainsKey("NPC - GUI Kits")) {
config["NPC - GUI Kits"] = GetExampleGUIKits();
Config.WriteObject(config);
}
if (!config.ContainsKey("CopyPaste - Parameters")) {
config["CopyPaste - Parameters"] = new List<string> {
"deployables", "true", "inventories", "true"
}
;
Config.WriteObject(config);
}
if (!config.ContainsKey("Custom AutoKits")) {
config["Custom AutoKits"] = new Dictionary<int, string> {
{
0, "KitName"
}
, {
1, "KitName"
}
, {
2, "KitName"
}
}
;
Config.WriteObject(config);
}
if (!config.ContainsKey("UI KeyBinding")) {
config["UI KeyBinding"] = string.Empty;
Config.WriteObject(config);
}
if (!config.ContainsKey("Kit - Logging")) {
config["Kit - Logging"] = false;
Config.WriteObject(config);
}
if (!config.ContainsKey("Show All Kits")) {
config["Show All Kits"] = false;
Config.WriteObject(config);
}
if (!config.ContainsKey("Background - URL")) {
config["Background - URL"] = string.Empty;
Config.WriteObject(config);
}
var keys = config.Keys.ToArray();
if (keys.Length > 1) {
foreach (var key in keys) {
if (!key.Equals("NPC - GUI Kits") && !key.Equals("CopyPaste - Parameters") && !key.Equals("Custom AutoKits") && !key.Equals("UI KeyBinding") && !key.Equals("Background - URL") && !key.Equals("Kit - Logging") && !key.Equals("Show All Kits")) config.Remove(key);
}
Config.WriteObject(config);
}
CopyPasteParameters = JsonConvert.DeserializeObject<List<string>>(JsonConvert.SerializeObject(config["CopyPaste - Parameters"]));
GUIKits = JsonConvert.DeserializeObject<Dictionary<ulong, GUIKit>>(JsonConvert.SerializeObject(config["NPC - GUI Kits"]));
AutoKits = JsonConvert.DeserializeObject<Dictionary<int, string>>(JsonConvert.SerializeObject(config["Custom AutoKits"]));
UIKeyBinding = JsonConvert.DeserializeObject<string>(JsonConvert.SerializeObject(config["UI KeyBinding"]));
BackgroundURL = JsonConvert.DeserializeObject<string>(JsonConvert.SerializeObject(config["Background - URL"]));
KitLogging = JsonConvert.DeserializeObject<bool>(JsonConvert.SerializeObject(config["Kit - Logging"]));
ShowUnavailableKits = JsonConvert.DeserializeObject<bool>(JsonConvert.SerializeObject(config["Show All Kits"]));
}
static Dictionary<ulong, GUIKit> GetExampleGUIKits() {
return new Dictionary<ulong, GUIKit> {
{
0, new GUIKit {
kits = {
"kit1", "kit2"
}
, description = "Welcome on this server! Here is a list of free kits that you can get.<color=green>Enjoy your stay</color>"
}
}
, {
1235439, new GUIKit {
kits = {
"kit1", "kit2"
}
, description = "Welcome on this server! Here is a list of free kits that you can get.<color=green>Enjoy your stay</color>"
}
}
, {
8753201223, new GUIKit {
kits = {
"kit1", "kit3"
}
, description = "<color=red>VIPs Kits</color>"
}
}
}
;
}
void OnPlayerRespawned(BasePlayer player) {
var thereturn = Interface.Oxide.CallHook("canRedeemKit", player);
if (thereturn == null) {
if (storedData.Kits.ContainsKey("autokit")) {
player.inventory.Strip();
GiveKit(player, "autokit");
var item = player.inventory.AllItems().FirstOrDefault(p => p.info.shortname.Contains("detonator"));
if (item == null) return;
if (item.GetHeldEntity() == null) return;
item.GetHeldEntity().GetComponent<global : : Detonator>().frequency = (int) plugins.Find("Detonator").Call("GetFrequencyForPlayer", player);
item.GetHeldEntity().SendNetworkUpdate();
return;
}
foreach (var entry in AutoKits.OrderBy(k=>k.Key)) {
var success = CanRedeemKit(player, entry.Value, true) as string;
if (success != null) continue;
player.inventory.Strip();
success = GiveKit(player, entry.Value) as string;
if (success != null) continue;
proccessKitGiven(player, entry.Value);
return;
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////
///// Language
//////////////////////////////////////////////////////////////////////////////////////////
string GetMsg(string key, object steamid = null) {
return lang.GetMessage(key, this, steamid == null ? null : steamid.ToString());
}
Dictionary<string, string> messages = new Dictionary<string, string>() {
{
"title", "Kits: "
}
, {
"Name", "Name"
}
, {
"Description", "Description"
}
, {
"Redeem", "Redeem"
}
, {
"AddKit", "Add Kit"
}
, {
"Close", "Close"
}
, {
"NoKitsFound", "All Available Kits are already in this Menu!"
}
, {
"AddKitToMenu", "Select a Kit to Add to this Menu"
}
, {
"KitCooldown", "Cooldown: {0}"
}
, {
"Unavailable", "Unavailable"
}
, {
"Last", "Last"
}
, {
"Next", "Next"
}
, {
"Back", "Back"
}
, {
"First", "First"
}
, {
"RemoveKit", "Remove Kit?"
}
, {
"KitUses", "Uses: {0}"
}
, {
"NoInventorySpace", "You do not have enough inventory space for this Kit!"
}
, {
"Unlimited", "Unlimited"
}
, {
"None", "None"
}
, {
"KitRedeemed", "Kit Redeemed"
}
, {
"Emptykitname", "Empty Kit Name"
}
, {
"KitExistError", "This kit doesn't exist"
}
, {
"CantRedeemNow", "You are not allowed to redeem a kit at the moment"
}
, {
"NoAuthToRedeem", "You don't have the Auth Level to use this kit"
}
, {
"NoPermKit", "You don't have the permissions to use this kit"
}
, {
"NoRemainingUses", "You already redeemed all of these kits"
}
, {
"CooldownMessage", "You need to wait {0} seconds to use this kit"
}
, {
"NPCError", "You must find the NPC that gives this kit to redeem it."
}
, {
"PastingError", "Something went wrong while pasting, is CopyPaste installed?"
}
, {
"NoKitFound", "This kit doesn't exist"
}
,
}
;
private readonly Dictionary<int, string> _itemIdShortnameConversions = new Dictionary<int, string> {
[-1461508848]
= "rifle.ak", [2115555558] = "ammo.handmade.shell", [-533875561] = "ammo.pistol", [1621541165] = "ammo.pistol.fire", [-422893115] = "ammo.pistol.hv", [815896488] = "ammo.rifle", [805088543] = "ammo.rifle.explosive", [449771810] = "ammo.rifle.incendiary", [1152393492] = "ammo.rifle.hv", [1578894260] = "ammo.rocket.basic", [1436532208] = "ammo.rocket.fire", [542276424] = "ammo.rocket.hv", [1594947829] = "ammo.rocket.smoke", [-1035059994] = "ammo.shotgun", [1818890814] = "ammo.shotgun.fire", [1819281075] = "ammo.shotgun.slug", [1685058759] = "antiradpills", [93029210] = "apple", [-1565095136] = "apple.spoiled", [-1775362679] = "arrow.bone", [-1775249157] = "arrow.fire", [-1280058093] = "arrow.hv", [-420273765] = "arrow.wooden", [563023711] = "autoturret", [790921853] = "axe.salvaged", [-337261910] = "bandage", [498312426] = "barricade.concrete", [504904386] = "barricade.metal", [-1221200300] = "barricade.sandbags", [510887968] = "barricade.stone", [-814689390] = "barricade.wood", [1024486167] = "barricade.woodwire", [2021568998] = "battery.small", [97329] = "bbq", [1046072789] = "trap.bear", [97409] = "bed", [-1480119738] = "tool.binoculars", [1611480185] = "black.raspberries", [-1386464949] = "bleach", [93832698] = "blood", [-1063412582] = "blueberries", [-1887162396] = "blueprintbase", [-55660037] = "rifle.bolt", [919780768] = "bone.club", [-365801095] = "bone.fragments", [68998734] = "botabag", [-853695669] = "bow.hunting", [271534758] = "box.wooden.large", [-770311783] = "box.wooden", [-1192532973] = "bucket.water", [-307490664] = "building.planner", [707427396] = "burlap.shirt", [707432758] = "burlap.shoes", [-2079677721] = "cactusflesh", [-1342405573] = "tool.camera", [-139769801] = "campfire", [-1043746011] = "can.beans", [2080339268] = "can.beans.empty", [-171664558] = "can.tuna", [1050986417] = "can.tuna.empty", [-1693683664] = "candycaneclub", [523409530] = "candycane", [1300054961] = "cctv.camera", [-2095387015] = "ceilinglight", [1428021640] = "chainsaw", [94623429] = "chair", [1436001773] = "charcoal", [1711323399] = "chicken.burned", [1734319168] = "chicken.cooked", [-1658459025] = "chicken.raw", [-726947205] = "chicken.spoiled", [-341443994] = "chocholate", [1540879296] = "xmasdoorwreath", [94756378] = "cloth", [3059095] = "coal", [3059624] = "corn", [2045107609] = "clone.corn", [583366917] = "seed.corn", [2123300234] = "crossbow", [1983936587] = "crude.oil", [1257201758] = "cupboard.tool", [-1144743963] = "diving.fins", [-1144542967] = "diving.mask", [-1144334585] = "diving.tank", [1066729526] = "diving.wetsuit", [-1598790097] = "door.double.hinged.metal", [-933236257] = "door.double.hinged.toptier", [-1575287163] = "door.double.hinged.wood", [-2104481870] = "door.hinged.metal", [-1571725662] = "door.hinged.toptier", [1456441506] = "door.hinged.wood", [1200628767] = "door.key", [-778796102] = "door.closer", [1526866730] = "xmas.door.garland", [1925723260] = "dropbox", [1891056868] = "ducttape", [1295154089] = "explosive.satchel", [498591726] = "explosive.timed", [1755466030] = "explosives", [726730162] = "facialhair.style01", [-1034048911] = "fat.animal", [252529905] = "femalearmpithair.style01", [471582113] = "femaleeyebrow.style01", [-1138648591] = "femalepubichair.style01", [305916740] = "female_hairstyle_01", [305916742] = "female_hairstyle_03", [305916744] = "female_hairstyle_05", [1908328648] = "fireplace.stone", [-2078972355] = "fish.cooked", [-533484654] = "fish.raw", [1571660245] = "fishingrod.handmade", [1045869440] = "flamethrower", [1985408483] = "flameturret", [97513422] = "flare", [1496470781] = "flashlight.held", [1229879204] = "weapon.mod.flashlight", [-1722829188] = "floor.grill", [1849912854] = "floor.ladder.hatch", [-1266285051] = "fridge", [-1749787215] = "boots.frog", [28178745] = "lowgradefuel", [-505639592] = "furnace", [1598149413] = "furnace.large", [-1779401418] = "gates.external.high.stone", [-57285700] = "gates.external.high.wood", [98228420] = "gears", [1422845239] = "geiger.counter", [277631078] = "generator.wind.scrap", [115739308] = "burlap.gloves", [-522149009] = "gloweyes", [3175989] = "glue", [718197703] = "granolabar", [384204160] = "grenade.beancan", [-1308622549] = "grenade.f1", [-217113639] = "fun.guitar", [-1580059655] = "gunpowder", [-1832205789] = "male_hairstyle_01", [305916741] = "female_hairstyle_02", [936777834] = "attire.hide.helterneck", [-1224598842] = "hammer", [-1976561211] = "hammer.salvaged", [-1406876421] = "hat.beenie", [-1397343301] = "hat.boonie", [1260209393] = "bucket.helmet", [-1035315940] = "burlap.headwrap", [-1381682752] = "hat.candle", [696727039] = "hat.cap", [-2128719593] = "coffeecan.helmet", [-1178289187] = "deer.skull.mask", [1351172108] = "heavy.plate.helmet", [-450738836] = "hat.miner", [-966287254] = "attire.reindeer.headband", [340009023] = "riot.helmet", [124310981] = "hat.wolf", [1501403549] = "wood.armor.helmet", [698310895] = "hatchet", [523855532] = "hazmatsuit", [2045246801] = "clone.hemp", [583506109] = "seed.hemp", [-148163128] = "attire.hide.boots", [-132588262] = "attire.hide.skirt", [-1666761111] = "attire.hide.vest", [-465236267] = "weapon.mod.holosight", [-1211618504] = "hoodie", [2133577942] = "hq.metal.ore", [-1014825244] = "humanmeat.burned", [-991829475] = "humanmeat.cooked", [-642008142] = "humanmeat.raw", [661790782] = "humanmeat.spoiled", [-1440143841] = "icepick.salvaged", [569119686] = "bone.armor.suit", [1404466285] = "heavy.plate.jacket", [-1616887133] = "jacket.snow", [-1167640370] = "jacket", [-1284735799] = "jackolantern.angry", [-1278649848] = "jackolantern.happy", [776005741] = "knife.bone", [108061910] = "ladder.wooden.wall", [255101535] = "trap.landmine", [-51678842] = "lantern", [-789202811] = "largemedkit", [516382256] = "weapon.mod.lasersight", [50834473] = "leather", [-975723312] = "lock.code", [1908195100] = "lock.key", [-1097452776] = "locker", [146685185] = "longsword", [-1716193401] = "rifle.lr300", [193190034] = "lmg.m249", [371156815] = "pistol.m92", [3343606] = "mace", [825308669] = "machete", [830965940] = "mailbox", [1662628660] = "male.facialhair.style02", [1662628661] = "male.facialhair.style03", [1662628662] = "male.facialhair.style04", [-1832205788] = "male_hairstyle_02", [-1832205786] = "male_hairstyle_04", [1625090418] = "malearmpithair.style01", [-1269800768] = "maleeyebrow.style01", [429648208] = "malepubichair.style01", [-1832205787] = "male_hairstyle_03", [-1832205785] = "male_hairstyle_05", [107868] = "map", [997973965] = "mask.balaclava", [-46188931] = "mask.bandana", [-46848560] = "metal.facemask", [-2066726403] = "bearmeat.burned", [-2043730634] = "bearmeat.cooked", [1325935999] = "bearmeat", [-225234813] = "deermeat.burned", [-202239044] = "deermeat.cooked", [-322501005] = "deermeat.raw", [-1851058636] = "horsemeat.burned", [-1828062867] = "horsemeat.cooked", [-1966381470] = "horsemeat.raw", [968732481] = "meat.pork.burned", [991728250] = "meat.pork.cooked", [-253819519] = "meat.boar", [-1714986849] = "wolfmeat.burned", [-1691991080] = "wolfmeat.cooked", [179448791] = "wolfmeat.raw", [431617507] = "wolfmeat.spoiled", [688032252] = "metal.fragments", [-1059362949] = "metal.ore", [1265861812] = "metal.plate.torso", [374890416] = "metal.refined", [1567404401] = "metalblade", [-1057402571] = "metalpipe", [-758925787] = "mining.pumpjack", [-1411620422] = "mining.quarry", [88869913] = "fish.minnows", [-2094080303] = "smg.mp5", [843418712] = "mushroom", [-1569356508] = "weapon.mod.muzzleboost", [-1569280852] = "weapon.mod.muzzlebrake", [449769971] = "pistol.nailgun", [590532217] = "ammo.nailgun.nails", [3387378] = "note", [1767561705] = "burlap.trousers", [106433500] = "pants", [-1334615971] = "heavy.plate.pants", [-135651869] = "attire.hide.pants", [-1595790889] = "roadsign.kilt", [-459156023] = "pants.shorts", [106434956] = "paper", [-578028723] = "pickaxe", [-586116979] = "jar.pickle", [-1379225193] = "pistol.eoka", [-930579334] = "pistol.revolver", [548699316] = "pistol.semiauto", [142147109] = "planter.large", [148953073] = "planter.small", [102672084] = "attire.hide.poncho", [640562379] = "pookie.bear", [-1732316031] = "xmas.present.large", [-2130280721] = "xmas.present.medium", [-1725510067] = "xmas.present.small", [1974032895] = "propanetank", [-225085592] = "pumpkin", [509654999] = "clone.pumpkin", [466113771] = "seed.pumpkin", [2033918259] = "pistol.python", [2069925558] = "target.reactive", [-1026117678] = "box.repair.bench", [1987447227] = "research.table", [540154065] = "researchpaper", [1939428458] = "riflebody", [-288010497] = "roadsign.jacket", [-847065290] = "roadsigns", [3506021] = "rock", [649603450] = "rocket.launcher", [3506418] = "rope", [569935070] = "rug.bear", [113284] = "rug", [1916127949] = "water.salt", [-1775234707] = "salvaged.cleaver", [-388967316] = "salvaged.sword", [2007564590] = "santahat", [-1705696613] = "scarecrow", [670655301] = "hazmatsuit_scientist", [1148128486] = "hazmatsuit_scientist_peacekeeper", [-141135377] = "weapon.mod.small.scope", [109266897] = "scrap", [-527558546] = "searchlight", [-1745053053] = "rifle.semiauto", [1223860752] = "semibody", [-419069863] = "sewingkit", [-1617374968] = "sheetmetal", [2057749608] = "shelves", [24576628] = "shirt.collared", [-1659202509] = "shirt.tanktop", [2107229499] = "shoes.boots", [191795897] = "shotgun.double", [-1009492144] = "shotgun.pump", [2077983581] = "shotgun.waterpipe", [378365037] = "guntrap", [-529054135] = "shutter.metal.embrasure.a", [-529054134] = "shutter.metal.embrasure.b", [486166145] = "shutter.wood.a", [1628490888] = "sign.hanging.banner.large", [1498516223] = "sign.hanging", [-632459882] = "sign.hanging.ornate", [-626812403] = "sign.pictureframe.landscape", [385802761] = "sign.pictureframe.portrait", [2117976603] = "sign.pictureframe.tall", [1338515426] = "sign.pictureframe.xl", [-1455694274] = "sign.pictureframe.xxl", [1579245182] = "sign.pole.banner.large", [-587434450] = "sign.post.double", [-163742043] = "sign.post.single", [-1224714193] = "sign.post.town", [644359987] = "sign.post.town.roof", [-1962514734] = "sign.wooden.huge", [-705305612] = "sign.wooden.large", [-357728804] = "sign.wooden.medium", [-698499648] = "sign.wooden.small", [1213686767] = "weapon.mod.silencer", [386382445] = "weapon.mod.simplesight", [1859976884] = "skull_fire_pit", [960793436] = "skull.human", [1001265731] = "skull.wolf", [1253290621] = "sleepingbag", [470729623] = "small.oil.refinery", [1051155022] = "stash.small", [865679437] = "fish.troutsmall", [927253046] = "smallwaterbottle", [109552593] = "smg.2", [-2092529553] = "smgbody", [691633666] = "snowball", [-2055888649] = "snowman", [621575320] = "shotgun.spas12", [-2118132208] = "spear.stone", [-1127699509] = "spear.wooden", [-685265909] = "spikes.floor", [552706886] = "spinner.wheel", [1835797460] = "metalspring", [-892259869] = "sticks", [-1623330855] = "stocking.large", [-1616524891] = "stocking.small", [789892804] = "stone.pickaxe", [-1289478934] = "stonehatchet", [-892070738] = "stones", [-891243783] = "sulfur", [889398893] = "sulfur.ore", [-1625468793] = "supply.signal", [1293049486] = "surveycharge", [1369769822] = "fishtrap.small", [586484018] = "syringe.medical", [110115790] = "table", [1490499512] = "targeting.computer", [3552619] = "tarp", [1471284746] = "techparts", [456448245] = "smg.thompson", [110547964] = "torch", [1588977225] = "xmas.decoration.baubels", [918540912] = "xmas.decoration.candycanes", [-471874147] = "xmas.decoration.gingerbreadmen", [205978836] = "xmas.decoration.lights", [-1044400758] = "xmas.decoration.pinecone", [-2073307447] = "xmas.decoration.star", [435230680] = "xmas.decoration.tinsel", [-864578046] = "tshirt", [1660607208] = "tshirt.long", [260214178] = "tunalight", [-1847536522] = "vending.machine", [-496055048] = "wall.external.high.stone", [-1792066367] = "wall.external.high", [562888306] = "wall.frame.cell.gate", [-427925529] = "wall.frame.cell", [995306285] = "wall.frame.fence.gate", [-378017204] = "wall.frame.fence", [447918618] = "wall.frame.garagedoor", [313836902] = "wall.frame.netting", [1175970190] = "wall.frame.shopfront", [525244071] = "wall.frame.shopfront.metal", [-1021702157] = "wall.window.bars.metal", [-402507101] = "wall.window.bars.toptier", [-1556671423] = "wall.window.bars.wood", [61936445] = "wall.window.glass.reinforced", [112903447] = "water", [1817873886] = "water.catcher.large", [1824679850] = "water.catcher.small", [-1628526499] = "water.barrel", [547302405] = "waterjug", [1840561315] = "water.purifier", [-460592212] = "xmas.window.garland", [3655341] = "wood", [1554697726] = "wood.armor.jacket", [-1883959124] = "wood.armor.pants", [-481416622] = "workbench1", [-481416621] = "workbench2", [-481416620] = "workbench3", [-1151126752] = "xmas.lightstring", [-1926458555] = "xmas.tree"
}
;
//////////////////////////////////////////////////////////////////////////////////////////
///// Kit Creator
//////////////////////////////////////////////////////////////////////////////////////////
static List<KitItem> GetPlayerItems(BasePlayer player) {
List<KitItem> kititems = new List<KitItem>();
foreach (Item item in player.inventory.containerWear.itemList) {
if (item != null) {
var iteminfo = ProcessItem(item, "wear");
kititems.Add(iteminfo);
}
}
foreach (Item item in player.inventory.containerMain.itemList) {
if (item != null) {
var iteminfo = ProcessItem(item, "main");
kititems.Add(iteminfo);
}
}
foreach (Item item in player.inventory.containerBelt.itemList) {
if (item != null) {
var iteminfo = ProcessItem(item, "belt");
kititems.Add(iteminfo);
}
}
return kititems;
}
static private KitItem ProcessItem(Item item, string container) {
KitItem iItem = new KitItem();
iItem.amount = item.amount;
iItem.mods = new List<int>();
iItem.container = container;
iItem.skinid = item.skin;
iItem.itemid = item.info.itemid;
iItem.weapon = false;
iItem.blueprintTarget = item.blueprintTarget;
if (item.info.category.ToString() == "Weapon") {
BaseProjectile weapon = item.GetHeldEntity() as BaseProjectile;
if (weapon != null) {
if (weapon.primaryMagazine != null) {
iItem.weapon = true;
if (item.contents != null) foreach (var mod in item.contents.itemList) {
if (mod.info.itemid != 0) iItem.mods.Add(mod.info.itemid);
}
}
}
}
return iItem;
}
//////////////////////////////////////////////////////////////////////////////////////////
///// Kit Redeemer
//////////////////////////////////////////////////////////////////////////////////////////
private class BoxItem {
[JsonProperty("Короткое название предмета")]
public string ShortName;
[JsonProperty("SkinID")]
public ulong SkinID;
[JsonProperty("Вес предмета в рандоме")]
public int Weight;
[JsonProperty("Количество патронов")]
public int AmmoAmount;
[JsonProperty("Тип.патронов")]
public string AmmoString;
[JsonProperty("Мин.количество")]
public int MinAmount;
[JsonProperty("Макс.количество")]
public int MaxAmount;
public Item ToItem() => ItemManager.CreateByName(ShortName, Oxide.Core.Random.Range(MinAmount, MaxAmount), SkinID);
}
private class BoxKit {
[JsonProperty("Минимальное число предметов")]
public int MinAmount = 1;
[JsonProperty("Максимальное число предметов")]
public int MaxAmount = 5;
[JsonProperty("Возможные для выпадения предметы")]
public List<BoxItem> Items = new List<BoxItem>();
public BoxItem GetControlRandom() {
int maxChance = Items.Sum(p => p.Weight);
int rChance = Oxide.Core.Random.Range(0, maxChance);
int curChance = 0;
foreach (var check in Items.OrderBy(p => p.Weight)) {
if (check.Weight + curChance > rChance) return check;
curChance += check.Weight;
}
Interface.Oxide.LogError($"Unable to find random weight item ([{maxChance}/{rChance}/{curChance}])");
return Items.GetRandom();
}
public void ProcessItems(ItemContainer container) {
for (int i = 0; i < Oxide.Core.Random.Range(MinAmount, MaxAmount);
i++) {
var random = GetControlRandom();
var item = random.ToItem();
item.MoveToContainer(container);
if (random.AmmoString.Length > 0) {
Item ammo = ItemManager.CreateByName(random.AmmoString, random.AmmoAmount);
ammo.MoveToContainer(container);
}
}
}
}
private BoxKit kitHome = new BoxKit {
MinAmount = 1, MaxAmount = 1, Items = new List<BoxItem> {
new BoxItem {
ShortName = "furnace", MinAmount = 1, AmmoString = "", AmmoAmount = 1, MaxAmount = 1, SkinID = 0UL, Weight = 25
}
}
}
;
private BoxKit kit = new BoxKit {
MinAmount = 1, MaxAmount = 1, Items = new List<BoxItem> {
new BoxItem {
ShortName = "bow.hunting", MinAmount = 1, AmmoString = "arrow.bone", AmmoAmount = 16, MaxAmount = 1, SkinID = 0UL, Weight = 25,
}
, new BoxItem {
ShortName = "pistol.nailgun", MinAmount = 1, AmmoString = "ammo.nailgun.nails", AmmoAmount = 50, MaxAmount = 1, SkinID = 0UL, Weight = 25
}
, new BoxItem {
ShortName = "pistol.eoka", MinAmount = 1, MaxAmount = 1, AmmoString = "ammo.handmade.shell", AmmoAmount = 4, SkinID = 0UL, Weight = 25
}
, new BoxItem {
ShortName = "pickaxe", MinAmount = 1, MaxAmount = 1, AmmoString = "", AmmoAmount = 1, SkinID = 0UL, Weight = 25
}
, new BoxItem {
ShortName = "hatchet", MinAmount = 1, MaxAmount = 1, AmmoString = "", AmmoAmount = 1, SkinID = 0UL, Weight = 25
}
,
}
}
;
void TryGiveKit(BasePlayer player, string kitname) {
var success = CanRedeemKit(player, kitname) as string;
if (success != null) {
return;
}
success = GiveKit(player, kitname) as string;
if (success != null) {
return;
}
Interface.CallHook("OnKitRedeemed", player, kitname);
proccessKitGiven(player, kitname);
Effect.server.Run("assets/bundled/prefabs/fx/impacts/slash/cloth/cloth1.prefab", player.transform.position);
if (kitname.ToLower() == "стартовый") {
// ТУТ СНИЗУ ВОТ ЦИФЕРКУ КОТОРАЯ БУДЕТ V ТУТ ПОМЕНЯТЬ НА ЛЮБУЮ ДРУГУЮ
if (Oxide.Core.Random.Range(0, 100) > 25) return;
kit.ProcessItems(player.inventory.containerMain);
}
if (kitname.ToLower() == "дом") {
// ТУТ СНИЗУ ВОТ ЦИФЕРКУ КОТОРАЯ БУДЕТ V ТУТ ПОМЕНЯТЬ НА ЛЮБУЮ ДРУГУЮ
if (Oxide.Core.Random.Range(0, 100) > 25) return;
kitHome.ProcessItems(player.inventory.containerMain);
}
}
void proccessKitGiven(BasePlayer player, string kitname) {
if (string.IsNullOrEmpty(kitname)) return;
kitname = kitname.ToLower();
Kit kit;
if (!storedData.Kits.TryGetValue(kitname, out kit)) return;
var kitData = GetKitData(player.userID, kitname);
if (kit.max > 0) kitData.max += 1;
if (kit.cooldown > 0) kitData.cooldown = CurrentTime() + kit.cooldown;
if (PlayerGUI.ContainsKey(player.userID) && PlayerGUI[player.userID].open) RefreshKitPanel(player, PlayerGUI[player.userID].guiid, PlayerGUI[player.userID].page);
}
private object GiveKit(BasePlayer player, string kitname) {
if (string.IsNullOrEmpty(kitname)) return GetMsg("Emptykitname", player.userID);
kitname = kitname.ToLower();
Kit kit;
if (!storedData.Kits.TryGetValue(kitname, out kit)) return GetMsg("NoKitFound", player.userID);
foreach (var kitem in kit.items) {
GiveItem(player.inventory, kitem.weapon ? BuildWeapon(kitem.itemid, kitem.skinid, kitem.mods) : BuildItem(kitem.itemid, kitem.amount, kitem.skinid, kitem.blueprintTarget), kitem.container == "belt" ? player.inventory.containerBelt : kitem.container == "wear" ? player.inventory.containerWear : player.inventory.containerMain);
}
if (!string.IsNullOrEmpty(kit.building)) {
var success = CopyPaste?.CallHook("TryPasteFromSteamID", player.userID, kit.building, CopyPasteParameters.ToArray());
return success;
}
if (KitLogging) LogToFile("received", $"{player.displayName}<{player.UserIDString}> - Received Kit: {kitname}", this);
return true;
}
bool GiveItem(PlayerInventory inv, Item item, ItemContainer container = null) {
if (item == null) {
return false;
}
int position = -1;
return (((container != null) && item.MoveToContainer(container, position, true)) || (item.MoveToContainer(inv.containerMain, -1, true) || item.MoveToContainer(inv.containerBelt, -1, true)));
}
private Item BuildItem(int itemid, int amount, ulong skin, int blueprintTarget) {
if (amount < 1) amount = 1;
Item item = CreateByItemID(itemid, amount, skin);
if (blueprintTarget != 0) item.blueprintTarget = blueprintTarget;
return item;
}
private Item BuildWeapon(int id, ulong skin, List<int> mods) {
Item item = CreateByItemID(id, 1, skin);
var weapon = item.GetHeldEntity() as BaseProjectile;
if (weapon != null) {
(item.GetHeldEntity() as BaseProjectile).primaryMagazine.contents = (item.GetHeldEntity() as BaseProjectile).primaryMagazine.capacity;
}
if (mods != null) {
foreach (var mod in mods) {
item.contents.AddItem(BuildItem(mod, 1, 0, 0).info, 1);
}
}
return item;
}
private Item CreateByItemID(int itemID, int amount = 1, ulong skin = 0) {
string shortName = "";
if (_itemIdShortnameConversions.TryGetValue(itemID, out shortName)) {
return ItemManager.CreateByName(shortName, amount, skin);
}
else {
return ItemManager.CreateByItemID(itemID, amount, skin);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
///// Check Kits
//////////////////////////////////////////////////////////////////////////////////////////
bool isKit(string kitname) {
return !string.IsNullOrEmpty(kitname) && storedData.Kits.ContainsKey(kitname.ToLower());
}
static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
static double CurrentTime() {
return DateTime.UtcNow.Subtract(epoch).TotalSeconds;
}
bool CanSeeKit(BasePlayer player, string kitname, bool fromNPC, out string reason) {
reason = string.Empty;
if (string.IsNullOrEmpty(kitname)) return false;
kitname = kitname.ToLower();
Kit kit;
if (!storedData.Kits.TryGetValue(kitname, out kit)) return false;
if (kit.hide) return false;
if (kit.authlevel > 0) if (player.net.connection.authLevel < kit.authlevel) return false;
if (!string.IsNullOrEmpty(kit.permission)) if (player.net.connection.authLevel < 2 && !permission.UserHasPermission(player.UserIDString, kit.permission)) return false;
if (kit.npconly && !fromNPC) return false;
if (kit.max > 0) {
int left = GetKitData(player.userID, kitname).max;
if (left >= kit.max) {
reason += "- 0 left";
return false;
}
reason += $"- {(kit.max - left)} left";
}
if (kit.cooldown > 0) {
double cd = GetKitData(player.userID, kitname).cooldown;
double ct = CurrentTime();
if (cd > ct && cd != 0.0) {
reason += $"- {Math.Abs(Math.Ceiling(cd - ct))} seconds";
return false;
}
}
return true;
}
object CanRedeemKit(BasePlayer player, string kitname, bool skipAuth = false) {
if (string.IsNullOrEmpty(kitname)) return GetMsg("Emptykitname", player.userID);
kitname = kitname.ToLower();
Kit kit;
if (!storedData.Kits.TryGetValue(kitname, out kit)) return GetMsg("KitExistError", player.userID);
object thereturn = Interface.Oxide.CallHook("canRedeemKit", player);
if (thereturn != null) {
if (thereturn is string) return thereturn;
return GetMsg("CantRedeemNow", player.userID);
}
if (kit.authlevel > 0 && !skipAuth) if (player.net.connection.authLevel < kit.authlevel) return GetMsg("NoAuthToRedeem", player.userID);
if (!string.IsNullOrEmpty(kit.permission)) if (player.net.connection.authLevel < 2 && !permission.UserHasPermission(player.UserIDString, kit.permission)) return GetMsg("NoPermKit", player.userID);
var kitData = GetKitData(player.userID, kitname);
if (kit.max > 0) if (kitData.max >= kit.max) return GetMsg("NoRemainingUses", player.userID);
if (kit.cooldown > 0) {
var ct = CurrentTime();
if (kitData.cooldown > ct && kitData.cooldown != 0.0) return string.Format(GetMsg("CooldownMessage", player.userID), Math.Abs(Math.Ceiling(kitData.cooldown - ct)));
}
if (kit.npconly) {
bool foundNPC = false;
var neededNpc = new List<ulong>();
foreach (var pair in GUIKits) {
if (pair.Value.kits.Contains(kitname)) neededNpc.Add(pair.Key);
}
foreach (var col in Physics.OverlapSphere(player.transform.position, 3f, playerLayer, QueryTriggerInteraction.Collide)) {
var targetplayer = col.GetComponentInParent<BasePlayer>();
if (targetplayer == null) continue;
if (neededNpc.Contains(targetplayer.userID)) {
foundNPC = true;
break;
}
}
if (!foundNPC) return GetMsg("NPCError", player.userID);
}
int beltcount = kit.items.Where(k => k.container == "belt").Count();
int wearcount = kit.items.Where(k => k.container == "wear").Count();
int maincount = kit.items.Where(k => k.container == "main").Count();
int totalcount = beltcount + wearcount + maincount;
if ((player.inventory.containerBelt.capacity - player.inventory.containerBelt.itemList.Count) < beltcount || (player.inventory.containerWear.capacity - player.inventory.containerWear.itemList.Count) < wearcount || (player.inventory.containerMain.capacity - player.inventory.containerMain.itemList.Count) < maincount) if (totalcount > (player.inventory.containerMain.capacity - player.inventory.containerMain.itemList.Count)) {
player.ChatMessage($"У вас <color=orange>недостаточно места</color>");
return GetMsg("NoInventorySpace", player.userID);
}
return true;
}
//////////////////////////////////////////////////////////////////////////////////////
// Kit Class
//////////////////////////////////////////////////////////////////////////////////////
class KitItem {
public int itemid;
public string container;
public int amount;
public ulong skinid;
public bool weapon;
public int blueprintTarget;
public List<int> mods = new List<int>();
}
class Kit {
public string inside;
public string symbol;
public string name;
public string description;
public int max;
public double cooldown;
public int authlevel;
public bool hide;
public bool npconly;
public string permission;
public string image;
public string building;
public List<KitItem> items = new List<KitItem>();
}
//////////////////////////////////////////////////////////////////////////////////////
// Data Manager
//////////////////////////////////////////////////////////////////////////////////////
private void SaveKitsData() {
if (kitsData == null) return;
Interface.Oxide.DataFileSystem.WriteObject("Kits_Data", kitsData);
}
private StoredData storedData;
private Dictionary<ulong, Dictionary<string, KitData>> kitsData;
class StoredData {
public Dictionary<string, Kit> Kits = new Dictionary<string, Kit>();
}
class KitData {
public int max;
public double cooldown;
}
void ResetData() {
kitsData.Clear();
SaveKitsData();
}
void Unload() {
ServerMgr.Instance.StopAllCoroutines();
SaveKitsData();
foreach (var player in BasePlayer.activePlayerList.ToList()) {
DestroyAllGUI(player);
}
}
void OnServerSave() {
SaveKitsData();
}
void SaveKits() {
Interface.Oxide.DataFileSystem.WriteObject("Kits", storedData);
}
void LoadData() {
var kits = Interface.Oxide.DataFileSystem.GetFile("Kits");
try {
kits.Settings.NullValueHandling = NullValueHandling.Ignore;
storedData = kits.ReadObject<StoredData>();
var update = new List<string>();
foreach (var kit in storedData.Kits) {
if (!kit.Key.Equals(kit.Key.ToLower())) update.Add(kit.Key);
}
foreach (var key in update) {
storedData.Kits[key.ToLower()] = storedData.Kits[key];
storedData.Kits.Remove(key);
}
}
catch {
storedData = new StoredData();
}
kits.Settings.NullValueHandling = NullValueHandling.Include;
}
KitData GetKitData(ulong userID, string kitname) {
Dictionary<string, KitData> kitDatas;
if (!kitsData.TryGetValue(userID, out kitDatas)) kitsData[userID] = kitDatas = new Dictionary<string, KitData>();
KitData kitData;
if (!kitDatas.TryGetValue(kitname, out kitData)) kitDatas[kitname] = kitData = new KitData();
return kitData;
}
//////////////////////////////////////////////////////////////////////////////////////
// Kit Editor
//////////////////////////////////////////////////////////////////////////////////////
readonly Dictionary<ulong, string> kitEditor = new Dictionary<ulong, string>();
//////////////////////////////////////////////////////////////////////////////////////
// ImageLibrary Hooks ---->> Absolut
//////////////////////////////////////////////////////////////////////////////////////
private string TryForImage(string shortname, ulong skin = 99) {
if (shortname.Contains("http")) return shortname;
if (skin == 99) skin = (ulong)ResourceId;
return GetImage(shortname, skin, true);
}
public string GetImage(string shortname, ulong skin = 0, bool returnUrl = false) => (string)ImageLibrary.Call("GetImage", shortname.ToLower(), skin, returnUrl);
public bool HasImage(string shortname, ulong skin = 0) => (bool)ImageLibrary.Call("HasImage", shortname.ToLower(), skin);
public bool AddImage(string url, string shortname, ulong skin = 0) => (bool)ImageLibrary?.Call("AddImage", url, shortname.ToLower(), skin);
// ... [Code preview truncated due to length. Full source in attached file] ...