// Teleporter: a new object, the Teleport Pad. Place two; using one (E, "Teleport") takes you to your other one, once // every 30 seconds. Two pads per player. Pads are given by admins: /teleporter [player] gives two. // It shows how a plugin makes a new object out of a game one: the pad is a Small Stash (it keeps its storage, health // and raid rules) with its own name, colour, a model from the s&box cloud (a metal plate), and an action. // Install: copy this file into the server's data folder, plugins/Teleporter.cs. Settings: plugins/config/Teleporter.json // (Model: a model package of sbox.game; empty: the stash's own model, a small bag). // Script engine rules: test objects with != null, no static fields that change, callbacks with one parameter at most. using RustLegacy; public class TeleporterConfig { public string Model { get; set; } = "thebox.metalplatform"; public float CooldownSeconds { get; set; } = 30f; public int MaxPads { get; set; } = 2; } public class Teleporter : RustPlugin { const string PadId = "teleporter_pad"; TeleporterConfig _config; /// SteamID → RealTime of the last teleport. readonly Dictionary _lastUse = new Dictionary(); public override void OnLoaded() { _config = LoadConfig(); if ( _config.Model != "" ) UsePackage( _config.Model ); DefineItem( new PluginItem { Id = PadId, Base = "Small Stash", Title = "Teleport Pad", Description = "Place two. Use one to reach the other.", Tint = "#7a5cff", Model = _config.Model, UseLabel = "Teleport", } ); AddCommand( "teleporter", OnGive, "Give two Teleport Pads", true, "[player]" ); } List PadsOf( string steamId ) { var pads = new List(); foreach ( var placed in PlacedBy( steamId ) ) if ( IsItem( placed, PadId ) ) pads.Add( placed ); return pads; } public override bool? CanBuild( RustPlayer player, ItemDefinition item, Vector3 position ) { if ( item.DisplayTitle != "Teleport Pad" || PadsOf( player.SteamId ).Count < _config.MaxPads ) return null; Reply( player, $"You already have {_config.MaxPads} pads." ); return false; } public override void OnDeployableUse( RustPlayer player, GameObject deployable ) { if ( !IsItem( deployable, PadId ) ) return; if ( OwnerOf( deployable ) != player.SteamId ) { Reply( player, "This pad isn't yours." ); return; } GameObject other = null; foreach ( var pad in PadsOf( player.SteamId ) ) if ( pad != deployable ) other = pad; if ( other == null ) { Reply( player, "Place your second pad first." ); return; } float last = 0f; if ( _lastUse.TryGetValue( player.SteamId, out last ) && RealTime.Now - last < _config.CooldownSeconds ) { Reply( player, $"The pad is charging: {(int)(_config.CooldownSeconds - (RealTime.Now - last)) + 1} s." ); return; } _lastUse[player.SteamId] = RealTime.Now; player.Teleport( other.WorldPosition + Vector3.Up * 20f ); Reply( player, $"Teleported to your other pad ({MapCell( other.WorldPosition )})." ); } void OnGive( ChatCommand cmd ) { var target = cmd.Args.Length > 0 ? FindPlayer( cmd.Args[0] ) : cmd.Player; if ( target == null ) { Reply( cmd.Player, "No player called that." ); return; } Give( target, "Teleport Pad", 2 ); Reply( cmd.Player, $"Two Teleport Pads given to {target.DisplayName}." ); } }