// Remover: take down a piece of your own building or an object you placed, and get it back, after Legacy's RemoverTool.
// Look at it and type /remove (or press Server plugin key 3). Not while your base is raided: removing is refused for
// 5 minutes after an explosion hit one of your buildings, so a door cannot be pulled out mid raid.
// A foundation or a wall takes down what rests on it, and only the piece removed is given back.
// Admins remove anything, and /owner tells whose a piece or object is (after Legacy's Prod).
// Install: copy this file into the server's data folder, plugins/Remover.cs. Settings: plugins/config/Remover.json.
// Script engine rules: test objects with != null, no static fields that change, callbacks with one parameter at most.
using RustLegacy;
public class RemoverConfig
{
/// The removed piece or object goes back into the player's inventory.
public bool Refund { get; set; } = true;
/// Minutes without removing after an explosion hit one of the player's buildings.
public float RaidLockMinutes { get; set; } = 5f;
/// Reach of /remove and /owner, in meters.
public float Reach { get; set; } = 5f;
}
public class Remover : RustPlugin
{
RemoverConfig _config;
/// SteamID → RealTime of the last explosion on one of their buildings.
readonly Dictionary _lastHit = new Dictionary();
public override void OnLoaded()
{
_config = LoadConfig();
AddCommand( "remove", OnRemove, "Remove the piece or object you look at (yours)" );
AddCommand( "owner", OnOwner, "Whose is the piece or object you look at", true );
foreach ( var p in Players ) OnPlayerConnected( p );
}
public override void OnPlayerConnected( RustPlayer player ) => SetButton( player, "remove", "Remove", "/remove", 3 );
public override bool? CanDamageBuilding( GameObject target, RustLegacy.DamageInfo info )
{
// explosions only: a rock on a wall does nothing, and would let anyone block its owner's /remove
var owner = OwnerOf( target );
if ( owner != "" && info.Type == RustLegacy.DamageType.Explosion ) _lastHit[owner] = RealTime.Now;
return null; // only watching: the game's rules decide the damage
}
void OnRemove( ChatCommand cmd )
{
var p = cmd.Player;
var target = Aimed( p, _config.Reach );
var item = target != null ? PlacedItem( target ) : null;
if ( item == null ) { Reply( p, "Look at a piece of your building or an object you placed." ); return; }
var admin = IsAdmin( p );
if ( !admin && OwnerOf( target ) != p.SteamId ) { Reply( p, "This isn't yours." ); return; }
float hit = 0f;
if ( !admin && _lastHit.TryGetValue( p.SteamId, out hit ) && RealTime.Now - hit < _config.RaidLockMinutes * 60f )
{
Reply( p, $"Your base is being raided: removing is back in {(int)((_config.RaidLockMinutes * 60f - (RealTime.Now - hit)) / 60f) + 1} min." );
return;
}
if ( _config.Refund ) Give( p, item.DisplayTitle, 1 );
Demolish( target );
Reply( p, _config.Refund ? $"{item.DisplayTitle} removed and given back." : $"{item.DisplayTitle} removed." );
}
void OnOwner( ChatCommand cmd )
{
var target = Aimed( cmd.Player, 30f );
var item = target != null ? PlacedItem( target ) : null;
if ( item == null ) { Reply( cmd.Player, "Look at a piece or a placed object." ); return; }
var owner = OwnerOf( target );
var online = owner != "" ? FindPlayer( owner ) : null;
Reply( cmd.Player, owner == "" ? $"{item.DisplayTitle}: nobody's." : $"{item.DisplayTitle} of {(online != null ? online.DisplayName + " " : "")}({owner}), {PlacedBy( owner ).Count} pieces and objects." );
}
}