### Creating a Custom Entity System in C# Source: https://context7.com/space-wizards/space-station-14/llms.txt Illustrates the creation of a custom entity system in C#. Systems contain game logic, subscribe to component events, and operate on entities with specific components. This example shows initialization, event handling, and system updates. ```csharp using Content.Shared.Actions; using Content.Shared.Interaction; using Robust.Shared.Timing; namespace Content.Shared.MyModule; public sealed class MyCustomSystem : EntitySystem { [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly SharedInteractionSystem _interaction = default!; public override void Initialize() { base.Initialize(); // Subscribe to component events SubscribeLocalEvent(OnStartup); SubscribeLocalEvent(OnInteractHand); } private void OnStartup(Entity ent, ref ComponentStartup args) { // Initialize component when it starts ent.Comp.LocalTimer = (float)_timing.CurTime.TotalSeconds; } private void OnInteractHand(Entity ent, ref InteractHandEvent args) { // Handle player interaction if (args.Handled) return; ent.Comp.Counter++; Dirty(ent); // Mark component for network sync args.Handled = true; } public override void Update(float frameTime) { base.Update(frameTime); // Process all entities with MyCustomComponent var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var comp)) { comp.LocalTimer += frameTime; if (comp.Counter > 10) { // Remove the component after threshold RemCompDeferred(uid); } } } } ``` -------------------------------- ### YAML Single Line Comment Example Source: https://github.com/space-wizards/space-station-14/wiki/YAML-Crash-Course Demonstrates how to add single-line comments in YAML by preceding text with a '#'. This is useful for explaining specific configurations or temporarily disabling lines. ```yml foo: bar # Look a comment. ``` -------------------------------- ### YAML Dictionary Data Type Examples Source: https://github.com/space-wizards/space-station-14/wiki/YAML-Crash-Course Demonstrates the definition of a dictionary (key-value pairs) in YAML using colons ':'. It shows both simple key-value pairs and how to quote keys and values if they contain special characters. ```yml A: B C: D ``` ```yml "A": "B" "C": "D" ``` -------------------------------- ### YAML List Data Type Example Source: https://github.com/space-wizards/space-station-14/wiki/YAML-Crash-Course Shows how to define a list in YAML using a hyphen '-' prefix for each item. The items in the list can be simple strings or other YAML structures. ```yml - A - B - C ``` -------------------------------- ### Complex YAML Nesting Example (SS14 Entity) Source: https://github.com/space-wizards/space-station-14/wiki/YAML-Crash-Course A comprehensive example showcasing complex nesting of lists and dictionaries in YAML, as commonly found in Space Station 14 entity definitions. This includes lists of dictionaries and nested key-value pairs. ```yml # First, this entire thing is stored in a massive list. That's why there's a -. # We're looking at one entry, a dictionary. - type: entity # Simple key/value pairs. id: SMES name: SMES description: Stores power in its super-magnetic cells components: # AHA! A list in a key. Wow! # This list ALSO stores dictionaries. - type: Sprite sprite: Buildings/smes.rsi scale: 2, 2 layers: - state: smes - state: smes-display shader: unshaded # Input lights. - shader: unshaded state: smes-oc0 # Charge meter. - visible: false shader: unshaded state: smes-og1 # Output lights. - shader: unshaded state: smes-op0 - type: Icon sprite: Buildings/smes.rsi state: smes ``` -------------------------------- ### YAML Nesting Dictionaries and Lists Source: https://github.com/space-wizards/space-station-14/wiki/YAML-Crash-Course Provides examples of nesting dictionaries within lists and lists within dictionaries. It illustrates different formatting options for readability, such as placing the first key on the same line as the list item or on a new line. ```yml # Like this, first key on the same line. - A: B X: "Y" # Or like this, first key on a new line. - A: C X: "Z" ``` ```yml A: - "X" - "Y" - "Z" B: - "U" - "V" - "W" ``` -------------------------------- ### Define Custom Prototypes in YAML Source: https://context7.com/space-wizards/space-station-14/llms.txt Example of a YAML file defining a custom game mode prototype. It maps directly to the C# prototype definition, specifying values for ID, name, description, player counts, and starting equipment. ```yaml # Resources/Prototypes/GameModes/custom_mode.yml - type: customGameMode id: MyCustomMode name: Custom Game Mode description: A custom game mode with special rules minPlayers: 10 maxPlayers: 50 roundDuration: 3600 # seconds startingEquipment: - ClothingUniformJumpsuit - ToolboxEmergency - FlashlightLantern ``` -------------------------------- ### YAML String Data Type Examples Source: https://github.com/space-wizards/space-station-14/wiki/YAML-Crash-Course Illustrates the basic definition of a string in YAML and how to handle special characters like colons by enclosing the string in double quotes. It also mentions the difference between single and double quotes regarding escape sequences like '\n'. ```yml hello ``` ```yml "hello: hi" ``` -------------------------------- ### macOS Build Script (Release Debug without Mono Glue) Source: https://github.com/space-wizards/space-station-14/wiki/Notes-on-exports This bash script compiles Space Station 14 for macOS with 64-bit architecture, enabling Mono support for release debug builds. It uses scons and requires a specific Mono installation prefix. The script does not explicitly generate mono glue, implying it might be handled elsewhere or is not required for this specific build configuration. Dependencies include System, System.Core, System.Xml, System.Configuration, Mono.Security, System.Numerics, System.Runtime.Serialization, System.Data, Microsoft.CSharp, and mscorlib. ```bash #!/bin/bash export MONO64_PREFIX="/Library/Frameworks/Mono.framework/Versions/Current/" scons -j 4 bits=64 platform=osx module_mono_enabled=yes target=release_debug ``` -------------------------------- ### macOS Build Script (Release Debug) Source: https://github.com/space-wizards/space-station-14/wiki/Notes-on-exports This bash script compiles Space Station 14 for macOS with 64-bit architecture, enabling Mono support and generating mono glue. It utilizes scons for the build process and requires a specific Mono installation prefix. Dependencies include System, System.Core, System.Xml, System.Configuration, Mono.Security, System.Numerics, System.Runtime.Serialization, System.Data, Microsoft.CSharp, and mscorlib. ```bash #!/bin/bash set -e export MONO64_PREFIX="/Library/Frameworks/Mono.framework/Versions/Current/" scons -j 4 bits=64 platform=osx module_mono_enabled=yes mono_glue=no target=release_debug bin/godot.osx.opt.tools.64.mono --generate-mono-glue modules/mono/glue ``` -------------------------------- ### Define Canvas Shader with Stencil Test (YAML) Source: https://github.com/space-wizards/space-station-14/wiki/Shaders This YAML example demonstrates defining a 'canvas' shader prototype that includes specific stencil test parameters. The stencil configuration ('ref', 'op', 'func') allows for advanced rendering effects by controlling how the stencil buffer is read and modified. ```yaml - type: shader id: stencilDraw kind: canvas stencil: ref: 1 op: Keep func: NotEqual ``` -------------------------------- ### Initialize Client-Side Systems in C# Source: https://context7.com/space-wizards/space-station-14/llms.txt Manages initialization of client-specific managers, UI systems, and rendering components. It registers IoC dependencies, components, and systems, ignoring server-only prototypes. Dependencies include Robust.Client and Content.Client namespaces. ```csharp using Content.Client.Administration.Managers; using Content.Client.IoC; using Robust.Client; using Robust.Shared.IoC; namespace Content.Client.Entry; public sealed class EntryPoint : GameClient { [Dependency] private readonly IClientAdminManager _adminManager = default!; [Dependency] private readonly IComponentFactory _componentFactory = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; public override void PreInit() { // Register IoC dependencies ClientContentIoC.Register(Dependencies); } public override void Init() { Dependencies.BuildGraph(); Dependencies.InjectDependencies(this); // Register components and systems _componentFactory.DoAutoRegistrations(); _componentFactory.IgnoreMissingComponents(); // Ignore server-only prototypes _prototypeManager.RegisterIgnore("gameRule"); _prototypeManager.RegisterIgnore("objective"); _componentFactory.GenerateNetIds(); _adminManager.Initialize(); } public override void PostInit() { base.PostInit(); // Setup UI themes and input contexts ContentContexts.SetupContexts(_inputManager.Contexts); } public override void Update(ModUpdateLevel level, FrameEventArgs frameEventArgs) { if (level == ModUpdateLevel.PreEngine) { // Custom per-frame client updates } } } ``` -------------------------------- ### Initialize Server-Side Systems in C# Source: https://context7.com/space-wizards/space-station-14/llms.txt Handles database connections, admin systems, ban management, and other server-specific functionality. It registers server IoC dependencies, loads configuration presets, registers components, and initializes database connections and gameplay systems. Dependencies include Robust.Server and Content.Server namespaces. ```csharp using Content.Server.Administration.Managers; using Content.Server.Database; using Content.Server.IoC; using Robust.Server; using Robust.Shared.Configuration; namespace Content.Server.Entry; public sealed class EntryPoint : GameServer { [Dependency] private readonly IServerDbManager _dbManager = default!; [Dependency] private readonly IAdminManager _admin = default!; [Dependency] private readonly IBanManager _ban = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IComponentFactory _factory = default!; public override void PreInit() { // Register server IoC dependencies ServerContentIoC.Register(Dependencies); } public override void Init() { base.Init(); Dependencies.BuildGraph(); Dependencies.InjectDependencies(this); // Load configuration presets LoadConfigPresets(_cfg, _res, _log.GetSawmill("configpreset")); // Register components _factory.DoAutoRegistrations(); _factory.IgnoreMissingComponents("Visuals"); _factory.GenerateNetIds(); // Initialize database and connections _dbManager.Init(); _preferences.Init(); } public override void PostInit() { base.PostInit(); // Initialize gameplay systems _admin.Initialize(); _ban.Initialize(); _entSys.GetEntitySystem().PostInitialize(); } public override void Update(ModUpdateLevel level, FrameEventArgs frameEventArgs) { base.Update(level, frameEventArgs); if (level == ModUpdateLevel.FramePostEngine) { // Per-frame server updates _playTimeTracking.Update(); _connection.Update(); } } } ``` -------------------------------- ### Use Prototypes in Systems (C#) Source: https://context7.com/space-wizards/space-station-14/llms.txt Illustrates how to load and access custom prototypes within an EntitySystem using IPrototypeManager. It shows how to try to index a specific prototype by its ID and iterate through all prototypes of a given type. ```csharp // Using prototypes in systems public sealed class GameModeSystem : EntitySystem { [Dependency] private readonly IPrototypeManager _proto = default!; public void LoadGameMode(string modeId) { if (!_proto.TryIndex(modeId, out var mode)) { Logger.Error($"Game mode {modeId} not found!"); return; } Logger.Info($"Loading {mode.Name} for {mode.MinPlayers}-{mode.MaxPlayers} players"); // Access prototype data foreach (var equipment in mode.StartingEquipment) { Logger.Info($"Starting equipment: {equipment}"); } } public IEnumerable GetAllGameModes() { return _proto.EnumeratePrototypes(); } } ``` -------------------------------- ### Initial Component Definitions (C#) Source: https://github.com/space-wizards/space-station-14/wiki/Entity-and-Component-netcode Shows the initial, duplicated definitions of a component on both the server and client sides before implementing shared components for replication. This highlights the code duplication issue addressed by shared components. ```csharp // SERVER SIDE CODE. namespace Content.Server.GameObjects { public sealed class DooHickyComponent : Component { // Name, needed by all components. public sealed override string Name => "DooHicky"; // The property that we will be replicating. public bool Foo { get; set; } } } // CLIENT SIDE CODE. namespace Content.Client.GameObjects { public sealed class DooHickyComponent : Component { // Name, needed by all components. public sealed override string Name => "DooHicky"; // The property that we will be replicating. public bool Foo { get; set; } } } ``` -------------------------------- ### Entity Prototype Definition (YAML) Source: https://github.com/space-wizards/space-station-14/wiki/YAML-Prototype-Entity-schema Defines a basic entity prototype, specifying its type, name, associated C# class, and components like a sprite. This is a foundational example for creating game objects. ```yaml - type: entity name: Wrench class: Prototypes.Items.Tools.Wrench components: - type: sprite icon: wrench.png ``` -------------------------------- ### Creating a Custom Component in C# Source: https://context7.com/space-wizards/space-station-14/llms.txt Demonstrates how to create a custom component in C#. Components store data for entities and can be registered, networked, and automatically state-generated. They are essential for defining entity attributes without game logic. ```csharp using Robust.Shared.GameStates; using Content.Shared.Actions; namespace Content.Shared.MyModule; [RegisterComponent, NetworkedComponent, Access(typeof(MySystem))] [AutoGenerateComponentState] public sealed partial class MyCustomComponent : Component { /// /// Example counter that is automatically synced to clients /// [DataField, AutoNetworkedField] public int Counter = 0; /// /// Example entity reference /// [DataField] public EntityUid? TargetEntity; /// /// Non-networked data (server-only or client-only) /// public float LocalTimer; } ``` -------------------------------- ### Add Sprite and Icon Components for Visual Representation Source: https://github.com/space-wizards/space-station-14/wiki/Defining-Your-First-Item This YAML snippet shows how to add 'SpriteComponent' and 'IconComponent' to make the 'shardGlass' entity visible in the game world and in the spawn menu. It specifies the texture file to be used for both. ```yaml components: - type: Sprite texture: Resources/Textures/Objects/items/shardGlass.png - type: Icon texture: Resources/Textures/Objects/items/shardGlass.png ``` -------------------------------- ### Create Custom Prototypes (C#) Source: https://context7.com/space-wizards/space-station-14/llms.txt Defines a custom prototype for game modes using attributes like [Prototype] and [IdDataField]. This allows for defining game-specific data structures that can be loaded from YAML. Requires Robust.Shared.Prototypes and Robust.Shared.Localization. ```csharp using Robust.Shared.Prototypes; using Robust.Shared.Localization; namespace Content.Shared.MyModule; [Prototype] public sealed partial class CustomGameModePrototype : IPrototype { [IdDataField] public string ID { get; private set; } = default!; [DataField(required: true)] public LocId Name { get; private set; } = string.Empty; [DataField] public LocId? Description { get; private set; } [DataField] public int MinPlayers { get; private set; } = 1; [DataField] public int MaxPlayers { get; private set; } = 100; [DataField] public List StartingEquipment { get; private set; } = new(); [DataField] public TimeSpan RoundDuration { get; private set; } = TimeSpan.FromMinutes(90); } ``` -------------------------------- ### Actions System Implementation in C# Source: https://context7.com/space-wizards/space-station-14/llms.txt Defines and manages player-triggerable abilities with support for cooldowns, targeting, and validation. This system allows granting actions to entities and handling action events, including custom ones. Dependencies include Content.Shared.Actions and Content.Server namespaces. ```csharp using Content.Shared.Actions; using Content.Shared.Actions.Events; namespace Content.Server.MyModule; public sealed class MyActionSystem : EntitySystem { [Dependency] private readonly SharedActionsSystem _actions = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnStartup); SubscribeLocalEvent(OnCustomAction); } private void OnStartup(Entity ent, ref ComponentStartup args) { // Grant an action to the entity _actions.AddAction(ent, "ActionMyCustomAbility"); } private void OnCustomAction(MyCustomActionEvent args) { // Validate action can be performed if (!_actions.ValidateAction(args.Action)) return; // Perform action logic var performer = args.Performer; // Set cooldown _actions.SetCooldown(args.Action, TimeSpan.FromSeconds(5)); args.Handled = true; } } // Define the action event public sealed partial class MyCustomActionEvent : InstantActionEvent { } ``` -------------------------------- ### Use CVars in Systems (C#) Source: https://context7.com/space-wizards/space-station-14/llms.txt Demonstrates how to read, set, and subscribe to CVar value changes within an EntitySystem. It utilizes the IConfigurationManager for these operations. Ensure IConfigurationManager is injected. ```csharp // Using CVars in systems public sealed class GameConfigSystem : EntitySystem { [Dependency] private readonly IConfigurationManager _cfg = default!; public override void Initialize() { base.Initialize(); // Read CVar value var maxPlayers = _cfg.GetCVar(CCVars.MaxPlayers); Logger.Info($"Max players: {maxPlayers}"); // Set CVar value _cfg.SetCVar(CCVars.DebugOverlays, true); // Subscribe to CVar changes _cfg.OnValueChanged(CCVars.MaxPlayers, OnMaxPlayersChanged); } private void OnMaxPlayersChanged(int newValue) { Logger. Info($"Max players changed to: {newValue}"); } } ``` -------------------------------- ### Defining Entity Prototypes in YAML Source: https://context7.com/space-wizards/space-station-14/llms.txt Shows how to define entity prototypes using YAML files. This allows for content creation and modification without altering game code. Prototypes specify entity types, names, descriptions, parents, and components. ```yaml # Resources/Prototypes/Entities/MyEntities/custom_item.yml - type: entity id: CustomInteractiveItem name: Custom Item description: An item with custom interaction behavior parent: BaseItem components: - type: Sprite sprite: Objects/MyModule/custom_item.rsi state: icon - type: Item size: Small - type: MyCustomComponent counter: 0 - type: Tag tags: - CustomTag ``` -------------------------------- ### Inherit BaseItem Functionality for Shard Glass Source: https://github.com/space-wizards/space-station-14/wiki/Defining-Your-First-Item This YAML snippet demonstrates inheriting from the 'BaseItem' prototype. This is crucial for giving the 'shardGlass' entity standard item behaviors, such as being pick-up-able, without redefining common properties. ```yaml parent: BaseItem ``` -------------------------------- ### Entity Action Prototype Definition Source: https://context7.com/space-wizards/space-station-14/llms.txt Defines a custom entity action with a name, description, and a 5-second use delay. It utilizes the InstantAction component and triggers a custom event. ```yaml - type: entity id: ActionMyCustomAbility name: Custom Ability description: Activates a custom ability with a 5 second cooldown parent: BaseAction components: - type: InstantAction icon: Interface/Actions/my_custom_icon.png event: !type:MyCustomActionEvent useDelay: 5 ``` -------------------------------- ### C# Database Operations for Player Data Source: https://context7.com/space-wizards/space-station-14/llms.txt Provides asynchronous methods for loading, initializing, and saving player preferences and characters. It also includes a method to check for active player bans using server database manager. Handles potential exceptions during database operations. ```csharp using Content.Server.Database; using Content.Shared.Preferences; using Robust.Shared.Network; namespace Content.Server.MyModule; public sealed class PlayerDataSystem : EntitySystem { [Dependency] private readonly IServerDbManager _db = default!; public async Task LoadPlayerPreferencesAsync(NetUserId userId) { try { // Load player preferences from database var prefs = await _db.GetPlayerPreferencesAsync(userId, default); if (prefs == null) { // Initialize new preferences with default profile var defaultProfile = HumanoidCharacterProfile.DefaultWithSpecies(); prefs = await _db.InitPrefsAsync(userId, defaultProfile, default); } return prefs; } catch (Exception ex) { Logger.Error($"Failed to load preferences for {userId}: {ex}"); return null; } } public async Task SaveCharacterAsync(NetUserId userId, ICharacterProfile profile, int slot) { try { await _db.SaveCharacterSlotAsync(userId, profile, slot); } catch (Exception ex) { Logger.Error($"Failed to save character for {userId}: {ex}"); } } public async Task CheckPlayerBanAsync( NetUserId userId, IPAddress? address, ImmutableArray? hwId) { // Check if player has an active ban var ban = await _db.GetServerBanAsync(address, userId, hwId, null); if (ban != null && ban.ExpirationTime > DateTime.UtcNow) { return ban; } return null; } } ``` -------------------------------- ### C# Interaction System Event Handling Source: https://context7.com/space-wizards/space-station-14/llms.txt Handles various interaction events like empty hand clicks, using items, and after-interaction targeting. It checks for reachability and specific item components, and displays popups to the user. Dependencies include SharedInteractionSystem and SharedPopupSystem. ```csharp using Content.Shared.Interaction; using Content.Shared.Interaction.Events; using Content.Shared.Popups; namespace Content.Shared.MyModule; public sealed class MyInteractionSystem : EntitySystem { [Dependency] private readonly SharedInteractionSystem _interaction = default!; [Dependency] private readonly SharedPopupSystem _popup = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnInteractHand); SubscribeLocalEvent(OnInteractUsing); SubscribeLocalEvent(OnAfterInteract); } private void OnInteractHand(Entity ent, ref InteractHandEvent args) { // Handle empty hand interaction if (args.Handled) return; // Check if user can reach the entity if (!_interaction.InRangeUnobstructed(args.User, ent)) return; _popup.PopupEntity("You interact with the object!", ent, args.User); args.Handled = true; } private void OnInteractUsing(Entity ent, ref InteractUsingEvent args) { // Handle interaction with item in hand if (args.Handled) return; var used = args.Used; // Check for specific item if (HasComp(used)) { _popup.PopupEntity("You use the correct item!", ent, args.User); args.Handled = true; } } private void OnAfterInteract(Entity ent, ref AfterInteractEvent args) { // Handle clicking in world with this entity if (args.Handled || !args.CanReach) return; if (args.Target != null) { _popup.PopupEntity($"You target {Name(args.Target.Value)}!", ent, args.User); args.Handled = true; } } } ``` -------------------------------- ### Define and Send Component Network Message (C#) Source: https://github.com/space-wizards/space-station-14/wiki/Entity-and-Component-netcode Defines a serializable component message for network communication and demonstrates its usage. Ensure 'Directed' is set to true for the message to function correctly. The message is sent using `Component.SendNetworkMessage` and received via the `HandleMessage` virtual method. ```csharp [Serializable, NetSerializable] public class FooMessage : ComponentMessage { public FooMessage(int bar) { // REALLY IMPORTANT: SET DIRECTED = TRUE // ELSE IT WON'T WORK. Directed = true; Bar = bar; } public int Bar { get; } } ``` -------------------------------- ### Microwave Recipe Prototype Definition (YAML) Source: https://github.com/space-wizards/space-station-14/wiki/YAML-Prototype-Entity-schema Illustrates the structure for defining a microwave recipe prototype. It specifies the type of prototype, the resulting item, and the required ingredients with their quantities. ```yaml - type: microwave_recipe result: "hamburger" ingredients: - meat: 3 flour: 5 ``` -------------------------------- ### Define Replicated Component State (C#) Source: https://github.com/space-wizards/space-station-14/wiki/Entity-and-Component-netcode Defines the shared component and its state, which will be serialized and sent over the network. This reduces code duplication between client and server. The component state must be marked as serializable. ```csharp // SHARED CODE // We define a Shared component to reduce code duplication and scope things better. // For the sake of the example we will NOT be putting Foo in this shared component. // Keep in mind that a shared component is purely an organizational thing, it's not strictly necessary. public abstract class SharedDooHickyComponent : Component { // Name, needed by all components. public sealed override string Name => "DooHicky"; // Net ID, required to sync across the network. // Net IDs are used by the networking system to know which component is which. // We keep them in a single static class as constants for organizational purposes. // IMPORTANT: the type is uint?, NOT uint. The question mark means it's nullable. public sealed override uint? NetID => ContentNetIDs.DOO_HICKY; // Specify the type of the component state used. public sealed override Type StateType => typeof(DooHickyComponentState); // This is the component state, the class sent over the wire to contain the replicated data. // MUST be marked as serializable, else we can't send it over the wire. [Serializable, NetSerializable] protected sealed class DooHickyComponentState : ComponentState { // Bog standard readonly data class stuff, move along. public DooHickyComponentState(bool foo) : base(ContentNetIDs.DOO_HICKY) { Foo = foo; } public bool Foo { get; } } } // We should ALSO put a new Net ID definition in the ContentNetIDs class in Shared. // Just give it a new ID that doesn't conflict. // SERVER CODE // We use the shared component so we don't have to redefine a lot of things. public sealed class DooHickyComponent : SharedDooHickyComponent { // The property that we will be replicating. private bool _foo; // Make it a property so we can call Dirty() public bool Foo { get => _foo; set { _foo = value; // Dirty() signals to the networking system that this component's state has changed // and needs to be re-sent to clients. Dirty(); } } // Create the component state for the networking system. public override ComponentState GetComponentState() { return new DooHickyComponentState(_foo); } } // CLIENT CODE // We use the shared component so we don't have to redefine a lot of things. public sealed class DooHickyComponent : SharedDooHickyComponent { // The property that we will be replicating. public bool Foo { get; set; } // Called to load new data from a component state sent from the server. public override void HandleComponentState(ComponentState state) { Foo = ((DooHickyComponentState)state).Foo; } } ``` -------------------------------- ### Add MeleeWeapon Component for Combat Source: https://github.com/space-wizards/space-station-14/wiki/Defining-Your-First-Item This YAML snippet adds the 'MeleeWeaponComponent' to the 'shardGlass' entity, enabling it to function as a melee weapon. It configures the damage value that the weapon will inflict. ```yaml - type: MeleeWeapon damage: 5 ``` -------------------------------- ### Entity Prototype Definition in YAML Source: https://github.com/space-wizards/space-station-14/wiki/About-entities-and-components This YAML snippet defines an entity prototype for a toolbox. It includes basic properties like type, ID, name, and description, and lists the components attached to the entity, such as Sprite, Icon, Storage, and Item. Components can also have custom data defined within their respective mappings. ```yaml - type: entity name: "Electrical Toolbox With Handle" parent: BaseItem id: YellowToolboxItem description: A toolbox typically stocked with electrical gear components: - type: Sprite texture: Objects/Toolbox_y.png - type: Icon texture: Objects/Toolbox_y.png - type: Storage Capacity: 60 - type: Item Size: 9999 ``` -------------------------------- ### Handle Network Events Server-Side in C# Source: https://context7.com/space-wizards/space-station-14/llms.txt Implements the server-side logic for handling network events. This system subscribes to `RequestCustomActionEvent`, validates the request, performs the action, and then broadcasts the result using `CustomActionPerformedEvent`. ```csharp // Server-side handling public sealed class ServerCustomActionSystem : EntitySystem { public override void Initialize() { base.Initialize(); SubscribeNetworkEvent(OnRequestAction); } private void OnRequestAction(RequestCustomActionEvent msg, EntitySessionEventArgs args) { var player = args.SenderSession.AttachedEntity; if (player == null) return; var target = GetEntity(msg.Target); // Validate and perform action var result = PerformAction(player.Value, target); // Broadcast result to all clients var ev = new CustomActionPerformedEvent( GetNetEntity(player.Value), msg.Target, result ); RaiseNetworkEvent(ev); } private int PerformAction(EntityUid performer, EntityUid target) { // Server-side action logic return 1; } } ```