// Kits: kits players claim with /kit (or the "Kits" button of the inventory screen, Server plugin key 4), each with its // own waiting time. A kit can be kept for a group through a permission: "starter" for everyone, "vip" for the vip group // (permission kits.vip), "admin" for admins only (kits.admin). Players see the kits they cannot claim yet, locked. // Who is VIP: rl_perm add vip in the server console, or /group with Groups.cs. Kits and permissions are in // plugins/config/Kits.json; add a kit with "Permission": "kits.something" and grant it to any group (rl_perm grant). // Install: copy this file into the server's data folder, plugins/Kits.cs. // Script engine rules: test objects with != null, no static fields that change, callbacks with one parameter at most. using RustLegacy; public class KitItem { public string Item { get; set; } = ""; public int Amount { get; set; } = 1; } public class KitDef { public string Name { get; set; } = ""; public string Description { get; set; } = ""; /// Permission needed to claim it; empty: everyone. public string Permission { get; set; } = ""; /// Minutes before the same player can claim it again; 0: no wait. public float CooldownMinutes { get; set; } = 30f; /// Item whose icon the kit shows. public string Icon { get; set; } = ""; public List Items { get; set; } = new List(); } public class KitsConfig { public List Kits { get; set; } = new List { new KitDef { Name = "starter", Description = "Stone tools, a bow and food to get going", CooldownMinutes = 30f, Icon = "Stone Hatchet", Items = new List { I( "Stone Hatchet", 1 ), I( "Hunting Bow", 1 ), I( "Arrow", 20 ), I( "Cooked Chicken Breast", 5 ), I( "Bandage", 3 ) } }, new KitDef { Name = "vip", Description = "Kevlar, an MP5 and medkits, for VIP players", Permission = "kits.vip", CooldownMinutes = 60f, Icon = "Kevlar Vest", Items = new List { I( "Kevlar Helmet", 1 ), I( "Kevlar Vest", 1 ), I( "Kevlar Pants", 1 ), I( "Kevlar Boots", 1 ), I( "MP5A4", 1 ), I( "9mm Ammo", 120 ), I( "Large Medkit", 3 ) } }, new KitDef { Name = "admin", Description = "Everything to build and fight, for admins", Permission = "kits.admin", CooldownMinutes = 0f, Icon = "M4", Items = new List { I( "M4", 1 ), I( "556 Ammo", 250 ), I( "Explosive Charge", 5 ), I( "Wood", 1000 ), I( "Metal Fragments", 500 ) } }, }; static KitItem I( string item, int amount ) => new KitItem { Item = item, Amount = amount }; } public class KitsData { /// "SteamID kit" → unix seconds of the last claim. public Dictionary LastClaim { get; set; } = new Dictionary(); /// The vip group got kits.vip once: the server owner can take it back, it is not given again. public bool DefaultsGranted { get; set; } } public class Kits : RustPlugin { KitsConfig _config; KitsData _data; public override void OnLoaded() { _config = LoadConfig(); _data = LoadData(); foreach ( var kit in _config.Kits ) if ( kit.Permission != "" ) RegisterPermission( kit.Permission ); // the vip group gets its kit the first time only: the server owner may change it afterwards if ( !_data.DefaultsGranted ) { CreateGroup( "vip" ); GrantPermission( "vip", "kits.vip" ); _data.DefaultsGranted = true; SaveData( _data ); } AddCommand( "kit", OnKit, "Kits", false, "[name]" ); foreach ( var p in Players ) SetButton( p, "kits", "Kits", "/kit", 4 ); } public override void OnPlayerConnected( RustPlayer player ) => SetButton( player, "kits", "Kits", "/kit", 4 ); // TimeSpan is not available in the script engine: 10,000,000 ticks per second. long Now() => DateTime.UtcNow.Ticks / 10_000_000; bool Allowed( RustPlayer p, KitDef kit ) => kit.Permission == "" || HasPermission( p.SteamId, kit.Permission ); /// Seconds before this player can claim this kit again (0: now). long Wait( RustPlayer p, KitDef kit ) { var key = $"{p.SteamId} {kit.Name}"; if ( kit.CooldownMinutes <= 0f || !_data.LastClaim.ContainsKey( key ) ) return 0; return Math.Max( 0, _data.LastClaim[key] + (long)(kit.CooldownMinutes * 60f) - Now() ); } static string Time( long seconds ) => seconds >= 3600 ? $"{seconds / 3600} h {seconds % 3600 / 60} min" : seconds >= 60 ? $"{seconds / 60} min" : $"{seconds} s"; void OnKit( ChatCommand cmd ) { var p = cmd.Player; if ( cmd.Args.Length == 0 ) { Menu( p ); return; } KitDef kit = null; foreach ( var k in _config.Kits ) if ( string.Equals( k.Name, cmd.Arg( 0 ), StringComparison.OrdinalIgnoreCase ) ) kit = k; if ( kit == null ) { Reply( p, $"No kit called {cmd.Arg( 0 )}. /kit shows them." ); return; } if ( !Allowed( p, kit ) ) { Reply( p, $"The {kit.Name} kit is not for you (needs {kit.Permission})." ); return; } if ( p.IsDead ) { Reply( p, "Respawn first." ); return; } var wait = Wait( p, kit ); if ( wait > 0 ) { Reply( p, $"{kit.Name} again in {Time( wait )}." ); return; } foreach ( var item in kit.Items ) Give( p, item.Item, item.Amount ); _data.LastClaim[$"{p.SteamId} {kit.Name}"] = Now(); SaveData( _data ); Reply( p, $"Kit {kit.Name} received." ); CloseMenu( p ); } /// Every kit: claimable ones in color, waiting ones with their time, locked ones greyed with what unlocks them. void Menu( RustPlayer p ) { var menu = new PluginMenu { Title = "Kits", Text = $"Your groups: {string.Join( ", ", GroupsOf( p.SteamId ) )}{(IsAdmin( p ) ? " (admin)" : "")}" }; foreach ( var kit in _config.Kits ) { var label = $"{kit.Name}"; if ( !Allowed( p, kit ) ) label = $"{kit.Name} · locked"; else if ( Wait( p, kit ) > 0 ) label = $"{kit.Name} · {Time( Wait( p, kit ) )}"; menu.Buttons.Add( new PluginMenuButton { Label = label, Command = $"/kit {kit.Name}", Item = kit.Icon, Group = kit.Permission == "" ? "Everyone" : kit.Permission } ); } ShowMenu( p, menu ); } }