Confirmedusers
13,514
edits
Mirotworez (talk | contribs) m (add translate tag) |
Mirotworez (talk | contribs) (Marked this version for translation) |
||
Line 2: | Line 2: | ||
{{GameVersion|1.15}} | {{GameVersion|1.15}} | ||
<translate> | <translate> | ||
<!--T:1--> | |||
Ever wanted to know how to add a command to the game? If yes, this is the right place to get an answer. | Ever wanted to know how to add a command to the game? If yes, this is the right place to get an answer. | ||
== Preparations == | == Preparations == <!--T:2--> | ||
<!--T:3--> | |||
The idea is to add a command which makes it easier for your mates to locate you. Therefore we will spawn some particles alongside a playing sound, so others can see and hear where you are at the moment. | The idea is to add a command which makes it easier for your mates to locate you. Therefore we will spawn some particles alongside a playing sound, so others can see and hear where you are at the moment. | ||
<!--T:4--> | |||
You can download the required assets [https://wiki.vintagestory.at/images/1/16/Here_Assets.zip here]. Just extract them in your mods directory and you are good to go. | You can download the required assets [https://wiki.vintagestory.at/images/1/16/Here_Assets.zip here]. Just extract them in your mods directory and you are good to go. | ||
== Implementation == | == Implementation == <!--T:5--> | ||
<!--T:6--> | |||
First of all you need to add another mod to your workspace. I will use the modid <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. | First of all you need to add another mod to your workspace. I will use the modid <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--> | |||
As always we need to create a class extending <code>ModSystem</code>: | As always we need to create a class extending <code>ModSystem</code>: | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
Line 19: | Line 24: | ||
{ | { | ||
<!--T:8--> | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<!--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: | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
Line 30: | Line 37: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<!--T:10--> | |||
Now we need to register the command itself: | Now we need to register the command itself: | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
Line 39: | Line 47: | ||
{ | { | ||
}, Privilege.chat); | <!--T:11--> | ||
}, Privilege.chat); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<!--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 <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--> | |||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
public override void StartServerSide(ICoreServerAPI api) | public override void StartServerSide(ICoreServerAPI api) | ||
Line 56: | Line 67: | ||
byEntity.World.PlaySoundAt(sound, byEntity); // Play sound | byEntity.World.PlaySoundAt(sound, byEntity); // Play sound | ||
Vec3d pos = byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight, 0); // Setting up position to spawn particles | <!--T:14--> | ||
Vec3d pos = byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight, 0); // Setting up position to spawn particles | |||
Random rand = new Random(); | Random rand = new Random(); | ||
for (int i = 0; i < 100; i++) // Spawn 100 particles | for (int i = 0; i < 100; i++) // Spawn 100 particles | ||
Line 71: | Line 83: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<!--T:15--> | |||
If you want to learn more about how to use particles you can check out this [[Simple Particles|tutorial]]. | If you want to learn more about how to use particles you can check out this [[Simple Particles|tutorial]]. | ||
== Testing == | == Testing == <!--T:16--> | ||
<!--T:17--> | |||
Finally, we are ready to run our first test: | Finally, we are ready to run our first test: | ||
<!--T:18--> | |||
<youtube>XjHMtl6rSF4</youtube> | <youtube>XjHMtl6rSF4</youtube> | ||
== Download == | == Download == <!--T:19--> | ||
<!--T:20--> | |||
Feel free to try it out yourself: | Feel free to try it out yourself: | ||
<!--T:21--> | |||
[https://wiki.vintagestory.at/images/5/5f/Here_v1.1.zip Here_v1.1.zip] | [https://wiki.vintagestory.at/images/5/5f/Here_v1.1.zip Here_v1.1.zip] | ||
</translate> | </translate> | ||
{{Navbox/modding|Vintage Story}} | {{Navbox/modding|Vintage Story}} |