90
edits
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 | 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 | * Register a command for teleporting to spawn | ||
* Add the using statement for | * Add the using statement for TipMod | ||
* Access the ModLoader and retrieve | * Access the ModLoader and retrieve TipMod | ||
* Call the method provided by | * 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. | 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 | 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 | 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 == |
edits