Modding:World Access: Difference between revisions

From Vintage Story Wiki
m
Update Code
m (Update Code)
(One intermediate revision by one other user not shown)
Line 4: Line 4:


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     public class SampleMod : ModBase
     public class SampleMod : ModSystem
     {
     {
         ICoreServerAPI api;
         ICoreServerAPI api;
Line 25: Line 25:
* during world generation we'd have to register to the [[WorldGen API|appropriate world gen events]].
* during world generation we'd have to register to the [[WorldGen API|appropriate world gen events]].
* when the player runs a custom command we need to register one: <code>api.RegisterCommand("test", "a test command", "", OnCommand);</code>
* when the player runs a custom command we need to register one: <code>api.RegisterCommand("test", "a test command", "", OnCommand);</code>
* when a player joins the game: <code>api.Event.PlayerJoin(OnPlayerJoin);</code>
* when a player joins the game: <code>api.Event.PlayerJoin += OnPlayerJoin;</code>


Let's register to the player join event.  
Let's register to the player join event.  
Line 33: Line 33:
         {
         {
             this.api = api;
             this.api = api;
             api.Event.PlayerJoin(OnPlayerJoin);
             api.Event.PlayerJoin += OnPlayerJoin;
         }
         }


Line 136: Line 136:
   
   
I hope this taught you the basics of accessing the world. More ways to access blocks and entities will be added here in the future.
I hope this taught you the basics of accessing the world. More ways to access blocks and entities will be added here in the future.
{{Navbox/modding|Vintage Story}}
1

edit