Aller au contenu
Morceaux d'émeute

Morceaux d'émeute

  • Maison
  • Nouvelles
  • Guides
  • Guides vidéo
  • Notes de mise à jour
  • Signaler un abus
  • Basculer le formulaire de recherche
Ingénieurs spatiaux

Ingénieurs spatiaux – Comment moder des objets usulaires (Interactions de blocs personnalisés)

Posté sur 07/29/2021 Par Gwindalmir Aucun commentaire sur Ingénieurs spatiaux – Comment moder des objets usulaires (Interactions de blocs personnalisés)
  • Titre: Ingénieurs spatiaux
  • Date de sortie: Février 28, 2019
  • Promoteur: Maison de logiciels Keen
  • Éditeur: Maison de logiciels Keen

This guide explains how to use the custom UseObjects added to the modding API in SE 1.199.

introduction

Since SE version 1.199, Keen added to the Modding API the ability to create custom UseObjects. A UseObject is an interactive point on a block, such as terminal access or a button on a button panel.

Si tu’ve ever made a block mod before, toi’ve probably made an interaction point. These are empties (dummies) nommé quelque chose comme detector_terminal_1.

This guide will show you how to create your own interaction dummies, which you can use to trigger any behavior you want that is possible with the ModAPI.

Model Preparation

The model setup is similar to any other interaction dummy you would make for regular blocks.
The only difference is the name of the empty/dummy.

  • Créer (or modify) a model
  • Add a new empty, following the same procedure for making any dummies
  • Name the empty according to the syntax described below.

The name of an interaction dummy is broken down into 3 or more parts: Marker, taper, subtype, sequence number (seq no); in this format: marker_type_subtype_sequencenumber.
Two parts are required to be named specifically: the marker and the sequence number.
Aux fins de ce guide, the marker is the detector, and seq no is an integer starting from 1.

UseObject Code Implementation

Once the model is set up, the actual interaction implementation is done via a C# script.

// Initialize the UseObject, using the type of "DHD"
// This must match the second element of the empty/dummy name, but is not case sensitive.
[MyUseObject("DHD")]
public class DHDUseObject : MyUseObjectBase
{
    IMyGps m_selectedButton;
    IMyTerminalBlock m_dhd;

    public DHDUseObject(IMyEntity owner, string dummyName, IMyModelDummy dummyData, uint key)
    : base(owner, dummyData)
    {
        // Save a reference to the parent block, so we can execute the action on the correct one later.
        m_dhd = owner as IMyTerminalBlock;
    }

    // This is the primary action, such as pushing a button.
    public override UseActionEnum PrimaryAction => UseActionEnum.Manipulate;

    // This is the secondary action, such as pressing K to open the action assignment menu of a button. Ceci est facultatif.
    public override UseActionEnum SecondaryAction => UseActionEnum.OpenTerminal;

    // This tells the game which actions you want to support. Dans ce cas, only the primary is used.
    // You can use specify multiple actions by combining them using a bitwise OR operator
    // par exemple., PrimaryAction | SecondaryAction
    public override UseActionEnum SupportedActions => PrimaryAction;

    // This is called when the player is aiming at the interaction dummy.
    public override MyActionDescription GetActionInfo(UseActionEnum actionEnum)
    {
        // This example doesn't care about the subtype ("bouton" in the model empty name),
        // However you can use that field, if set, to share one script with multiple dummy actions.
        // Par exemple, detector_mypower_on_1 could be used to turn a block on, et
        // detector_mypower_off_1 could be used to turn a block off. You could even have a 
        // a third one, detector_mypower_toggle_1 which toggles the block state.
        // You can grab the subtype field by splitting the dummy name on '_' and grabbing the third element (indice 2).
        changer (actionEnum)
        {
            case UseActionEnum.Manipulate:
                si (m_selectedButton == null)
                {
                    // Get the seq no of the dummy (spaces added to avoid Steam flagging as URL)
                    var button = int.Parse( this.Dummy .Name.Substring( this.Dummy .Name.LastIndexOf('_') + 1 ) ) - 1;
                    var button_text = "Bouton " + button.ToString();

                    // This creates a HUD marker for the interaction dummy, like button panels. Ceci est facultatif.
                    m_selectedButton = MyAPIGateway.Session.GPS.Create(button_text, "DHD Symbol", ActivationMatrix.Translation, vrai);
                    MyAPIGateway.Session.GPS.AddLocalGps(m_selectedButton);
                }
                autre
                {
                    m_selectedButton.Coords = ActivationMatrix.Translation;
                }

                // This section provides the HUD help text when the player aims at the interaction with Control Hints enabled.
                // Note, the game control key label is wrapped around [], which causes it to turn yellow in the notification.
                var hint = "Presse {0} to activate symbol on {1}";
                return new MyActionDescription()
                {
                    Text = MyStringId.GetOrCompute(indice),
                    FormatParams = new[] { "[" + MyAPIGateway.Input.GetGameControl(MyControlsSpace.USE) + "]", m_dhd?.DisplayNameText },
                    IsTextControlHint = true,
                };
            case UseActionEnum.OpenTerminal:
                return new MyActionDescription()
                {
                    Text = MySpaceTexts.NotificationHintPressToOpenControlPanel,
                    FormatParams = new [] { "[" + MyAPIGateway.Input.GetGameControl(MyControlsSpace.TERMINAL) + "]", m_dhd?.DefinitionDisplayNameText },
                    IsTextControlHint = true,
                };
            défaut:
                return default(MyActionDescription);
        }
    }

    // This is called when the player is no longer aiming at the interaction dummy.
    public override void OnSelectionLost()
    {
        // Remove the HUD marker
        if(m_selectedButton != nul)
            MyAPIGateway.Session.GPS.RemoveLocalGps(m_selectedButton);
        m_selectedButton = null;
    }

    // This is called when the player interacts with the object (presses the assigned keybind).
    public override void Use(UseActionEnum actionEnum, IMyEntity user)
    {
        changer (actionEnum)
        {
            case UseActionEnum.Manipulate:
                essayer
                {
                    var button = int.Parse( this.Dummy .Name.Substring( this.Dummy .Name.LastIndexOf('_') + 1 ) ) - 1;

                    // Place whatever code you want here to perform the action you wish to do.
                    // This example toggles the block On/Off action; note this example requires a MyFunctionalBlock,
                    // but you can use a regular MyTerminalBlock, depending on what you want to do.
                    m_dhd.Enabled = !m_dhd.Enabled
                }
                attraper(Exception)
                { /* avoid crashing the game, however you should write a message to the log */ }
                casser;
            case UseActionEnum.OpenTerminal:
                // There's no way to open the terminal just yet.
                casser;
        }
    }
}

Essai

Once you have the model, and code set up, you can load it up in the game, like you would any mod. The steps for creating a mod, en général, is outside the scope of this guide.

After you load it, you can view the dummy by enabling debug draw in the ModAPI debug menu (Shift-F11). But, and you should see your help text if you have Control Hints enabled in the game options. Push your assigned keybind on it, and watch it perform the action you want!

C'est tout ce que nous partageons aujourd'hui pour cela Ingénieurs spatiaux guide. Ce guide a été initialement créé et rédigé par Gwindalmir. Si nous ne parvenons pas à mettre à jour ce guide, vous pouvez trouver la dernière mise à jour en suivant ceci lien.

Si vous pensez que le contenu de ce site viole vos droits, y compris vos droits de propriété intellectuelle, veuillez nous contacter immédiatement en utilisant notre formulaire de contact.
Guides Mots clés:Ingénieurs spatiaux

Navigation de l’article

Post précédent: Guide de réalisation de Critter Crunch
Prochain article: Guide de réalisation omno

Laisser un commentaire Annuler la réponse

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

  • Titre: Ingénieurs spatiaux
  • Date de sortie: Février 28, 2019
  • Promoteur: Maison de logiciels Keen
  • Éditeur: Maison de logiciels Keen

Clause de non-responsabilité

Tout le contenu cité est dérivé de leurs sources respectives. Si vous pensez que nous avons utilisé votre contenu sans autorisation, assurez-vous de nous joindre et nous le prendrons au sérieux.
  • À propos de nous
  • Contactez-nous
  • politique de confidentialité
  • Conditions d'utilisation

droits d'auteur © 2025 Morceaux d'émeute.

Alimenté par Actualité PressBook Thème WordPress