Modding:Adding Code to the Player: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
(explicitly specify what each using directive is for)
(add note about c# knowledge)
Line 1: Line 1:
{{Modding Info}}
{{Modding Info}}
{{ambox
|type=This article presupposes some knowledge of [[Modding/C Sharp Scripting|C# scripting]].
|format=tiny}}


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

Revision as of 02:14, 10 October 2019

This page is about modding. See the modding overview for an abstract on modding.
This page is about modding. See the modding overview for an abstract on modding.
This article presupposes some knowledge of C# scripting.

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; // to abbreviate XRL.PlayerMutator and XRL.IPlayerMutator
  using XRL.World; // to abbreviate XRL.World.GameObject
  
  [PlayerMutator]
  public class MyPlayerMutator : IPlayerMutator
  {
      public void mutate(GameObject player)
      {
          // modify the player object before the game starts
      }
  }