// Creative: everyone can fly. A "Fly" button in the inventory screen and a key (Server plugin key 1, H by default) turn it // on and off; /fly does the same. Pair it with Give.cs (item menu) for a creative / build server. // Install: copy this file into the server's data folder, plugins/Creative.cs. Settings: plugins/config/Creative.json. // Script engine rules: test objects with != null, no static fields that change, callbacks with one parameter at most. using RustLegacy; public class CreativeConfig { /// Only admins (and the host of a lobby) may fly. public bool AdminOnly { get; set; } = false; /// Players are back in the air after a respawn if they were flying when they died. public bool KeepFlyingAfterDeath { get; set; } = true; } public class Creative : RustPlugin { CreativeConfig _config; /// SteamIDs of the players flying when they died. readonly HashSet _wasFlying = new HashSet(); public override void OnLoaded() { _config = LoadConfig(); AddCommand( "fly", OnFly, "Fly on or off", _config.AdminOnly ); foreach ( var p in Players ) ShowButton( p ); } public override void OnPlayerConnected( RustPlayer player ) => ShowButton( player ); bool Allowed( RustPlayer p ) => !_config.AdminOnly || IsAdmin( p ); void ShowButton( RustPlayer p ) { if ( !Allowed( p ) ) return; SetButton( p, "fly", p.IsFlying ? "Fly: ON" : "Fly: OFF", "/fly", 1 ); } void OnFly( ChatCommand cmd ) { var p = cmd.Player; if ( p.IsDead ) { Reply( p, "Respawn first." ); return; } SetFly( p, !p.IsFlying ); Reply( p, p.IsFlying ? "Flying: W A S D to move, Space up, Ctrl down, Shift faster." : "Back on your feet." ); ShowButton( p ); } public override void OnPlayerDeath( RustPlayer player, RustLegacy.DamageInfo info ) { if ( player.IsFlying ) _wasFlying.Add( player.SteamId ); } public override void OnPlayerRespawned( RustPlayer player ) { if ( _config.KeepFlyingAfterDeath && _wasFlying.Remove( player.SteamId ) && Allowed( player ) ) SetFly( player, true ); ShowButton( player ); } }