Modding:Adding Code to the Player: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
m (Egocarib moved page Modding:Adding Code to the Player to Modding: Adding Code to the Player: match formatting of other modding page titles)
m (add required using references)
Line 6: Line 6:


<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp">
  using XRL;
  using XRL.World;
 
   [PlayerMutator]
   [PlayerMutator]
   public class MyPlayerMutator : IPlayerMutator
   public class MyPlayerMutator : IPlayerMutator

Revision as of 22:19, 15 September 2019

You can use the [PlayerMutator] attribute and IPlayerMutator interface to modify the player object before the game begins, immediately after the player GameObject is first created.

This structure allows you to run custom code on the player object. For example, you might add custom parts to the player from your mod, which is otherwise very difficult to do.

Any class tagged with the PlayerMutator attribute is instantiated after the player object is created and assigned, and the "mutate" method is called with the player as the parameter. For example:

  using XRL;
  using XRL.World;
  
  [PlayerMutator]
  public class MyPlayerMutator : IPlayerMutator
  {
      public void mutate(GameObject player)
      {
          // modify the player object before the game starts
      }
  }