Modding:Commands: Difference between revisions

From Vintage Story Wiki
Undo revision 55424 by Mirotworez (talk)
m (add tvar tag)
(Undo revision 55424 by Mirotworez (talk))
Tag: Undo
Line 16: Line 16:


<!--T:6-->
<!--T:6-->
First of all you need to add another mod to your workspace. I will use the modid <tvar|1><code>here</code></>, so I will type in <tvar|2><code>add here</code></> in modtools to create a new mod. Additionally I will create <tvar|3><code>Command.cs</code></> in the <tvar|4><code>src</code></> directory.
First of all you need to add another mod to your workspace. I will use the modid <tvar|name><code>here</code></>, so I will type in <code>add here</code> in modtools to create a new mod. Additionally I will create <code>Command.cs</code> in the <code>src</code> directory.


<!--T:7-->
<!--T:7-->
As always we need to create a class extending <tvar|5><code>ModSystem</code></>:
As always we need to create a class extending <code>ModSystem</code>:
<tvar|6>
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
public class CommandMod : ModSystem
public class CommandMod : ModSystem
Line 28: Line 27:
}
}
</syntaxhighlight>
</syntaxhighlight>
</>


<!--T:9-->
<!--T:9-->
Commands are processed by the server, so our mod only needs to load on the server's side:
Commands are processed by the server, so our mod only needs to load on the server's side:
<tvar|7>
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
         public override bool ShouldLoad(EnumAppSide side)
         public override bool ShouldLoad(EnumAppSide side)
Line 39: Line 36:
         }
         }
</syntaxhighlight>
</syntaxhighlight>
</>


<!--T:10-->
<!--T:10-->
Now we need to register the command itself:
Now we need to register the command itself:
<tvar|8>
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
         public override void StartServerSide(ICoreServerAPI api)
         public override void StartServerSide(ICoreServerAPI api)
Line 56: Line 51:
         }
         }
</syntaxhighlight>
</syntaxhighlight>
</>


<!--T:12-->
<!--T:12-->
This command can be used by any player who is allowed to send a message (by default everyone). When a player types in <tvar|9><code>/here</code></>, the command will be executed. Now we the only thing missing is the actual code to spawn particles and to play the sound.
This command can be used by any player who is allowed to send a message (by default everyone). When a player types in <code>/here</code>, the command will be executed. Now we the only thing missing is the actual code to spawn particles and to play the sound.


<!--T:13-->
<!--T:13-->
<tvar|10>
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
         public override void StartServerSide(ICoreServerAPI api)
         public override void StartServerSide(ICoreServerAPI api)
Line 89: Line 82:
         }
         }
</syntaxhighlight>
</syntaxhighlight>
</>


<!--T:15-->
<!--T:15-->
Confirmedusers
13,514

edits