Modding:Moddable Mod: Difference between revisions

From Vintage Story Wiki
m
no edit summary
m (expanded draft)
mNo edit summary
Line 176: Line 176:
== Setting up SpawnMod ==
== Setting up SpawnMod ==


Before we get started, we have to add a reference to ModInfo. You can either reference the uncompiled project,
Before we get started, we have to add a reference to TipMod. You can either reference the uncompiled project,
or the compiled .dll file. If you are using Visual Studio, in your Solution Explorer, directly under your project,
or the compiled .dll file. If you are using Visual Studio, in your Solution Explorer, directly under your project,
right-click "References" and select "Add Reference".
right-click "References" and select "Add Reference".
Line 183: Line 183:


Next, we do the following
Next, we do the following
* Register a command for teleporting the player to spawn
* Register a command for teleporting to spawn
* Add the using statement for InfoMod
* Add the using statement for TipMod
* Access the ModLoader and retrieve InfoMod by using it's type
* Access the ModLoader and retrieve TipMod
* Call the method provided by InfoMod to describe our mod
* Call the method provided by TipMod to add our own tip


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
    class SpawnMod : ModSystem
    {
        public override void StartServerSide(ICoreServerAPI api)
        {
            base.StartServerSide(api);


            api.RegisterCommand("spawn", "Teleport to spawn", "", OnCmdSpawn);
            TipMod tipMod = api.ModLoader.GetModSystem<TipMod>();
            tipMod.AddTip(new Tip("codemeister32", "To quickly return to spawn, type /spawn"));
        }
        private void OnCmdSpawn(IServerPlayer player, int groupId, CmdArgs args)
        {
            player.Entity.TeleportTo(player.SpawnPosition);
        }
    }
</syntaxhighlight>
</syntaxhighlight>


Let's compile our mod and try it ingame. ? does only the includable need to be compiled ?
Let's compile our mod and try it ingame.
If we call /spawn and are teleported to spawn, our mod has been added successfuly. Next,
If we call /spawn and are teleported to spawn, our mod has been added successfuly. Next,
we can try calling /commandhere to see if SpawnMod successfuly described itself to InfoMod.
we can try calling /commandhere to see if SpawnMod successfuly described itself to TipMod.


- img -
- img -


Great! Next, we can add some code to make sure SpawnMod runs without InfoMod, if the user of our mod  
Great! Next, we can add some code to make sure SpawnMod runs without TipMod, if the user of our mod  
has not deemed it necessary to add.
has not deemed it necessary to add.


== Making SpawnMod not depend on InfoMod ==
== Making SpawnMod not depend on InfoMod ==