Modding:Commands/ru: Difference between revisions
Mirotworez (talk | contribs) (Created page with "== Подготовка ==") |
Mirotworez (talk | contribs) (Created page with "Идея состоит в том, чтобы добавить команду, которая облегчит вашим товарищам поиск вас. Поэтому...") |
||
Line 5: | Line 5: | ||
== Подготовка == | == Подготовка == | ||
Идея состоит в том, чтобы добавить команду, которая облегчит вашим товарищам поиск вас. Поэтому мы будем создавать некоторые частицы вместе с игровым звуком, чтобы другие могли видеть и слышать, где вы находитесь в данный момент. | |||
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. |
Revision as of 07:01, 26 August 2022
Эта страница проверялась в последний раз для версии Vintage Story 1.15.
Вы когда-нибудь хотели узнать, как добавить команду в игру? Если да, то это правильное место, чтобы получить ответ.
Подготовка
Идея состоит в том, чтобы добавить команду, которая облегчит вашим товарищам поиск вас. Поэтому мы будем создавать некоторые частицы вместе с игровым звуком, чтобы другие могли видеть и слышать, где вы находитесь в данный момент.
You can download the required assets here. Just extract them in your mods directory and you are good to go.
Implementation
First of all you need to add another mod to your workspace. I will use the modid here
, so I will type in add here
in modtools to create a new mod. Additionally I will create Command.cs
in the src
directory.
Как всегда нам нужно создать класс, расширяющий ModSystem
:
public class CommandMod : ModSystem
{
}
Команды обрабатываются сервером, поэтому нашему моду нужно загрузиться только на стороне сервера:
public override bool ShouldLoad(EnumAppSide side)
{
return side == EnumAppSide.Server;
}
Теперь нам нужно зарегистрировать саму команду:
public override void StartServerSide(ICoreServerAPI api)
{
base.StartServerSide(api);
api.RegisterCommand("here", "spawns particles around the player", "",
(IServerPlayer player, int groupId, CmdArgs args) =>
{
}, Privilege.chat);
}
Эту команду может использовать любой игрок, которому разрешено отправлять сообщения (по умолчанию все). Когда игрок вводит /here
, команда будет выполнена. Теперь нам не хватает только самого кода для создания частиц и воспроизведения звука.
public override void StartServerSide(ICoreServerAPI api)
{
base.StartServerSide(api);
AssetLocation sound = new AssetLocation("here", "sounds/partyhorn"); // Create sound location
api.RegisterCommand("here", "spawns particles around the player", "",
(IServerPlayer player, int groupId, CmdArgs args) =>
{
EntityPlayer byEntity = player.Entity;
byEntity.World.PlaySoundAt(sound, byEntity); // Play sound
Vec3d pos = byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight, 0); // Setting up position to spawn particles
Random rand = new Random();
for (int i = 0; i < 100; i++) // Spawn 100 particles
{
Vec3d realPos = pos.AddCopy(-0.1 + rand.NextDouble() * 0.2, 0, -0.1 + rand.NextDouble() * 0.2);
Vec3f velocity = new Vec3f(-0.2F + (float) rand.NextDouble() * 0.4F, 0.4F + (float) rand.NextDouble() * 2F, -0.2F + (float) rand.NextDouble() * 0.4F);
byEntity.World.SpawnParticles(1, ColorUtil.ColorFromRgba(255, rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)),
realPos, realPos,
velocity, velocity, (float) rand.NextDouble()*1 + 1, 0.01F,
1, EnumParticleModel.Cube);
}
}, Privilege.chat);
}
Если вы хотите узнать больше о том, как использовать частицы, вы можете ознакомиться с этим учебником.
Тестирование
Наконец, мы готовы запустить наш первый тест:
Скачать
Не стесняйтесь попробовать это самостоятельно:
Wondering where some links have gone?
The modding navbox is going through some changes! Check out Navigation Box Updates for more info and help finding specific pages.
Modding | |
---|---|
Modding Introduction | Getting Started • Пакет тем |
Content Modding | Content Mods • Developing a Content Mod • Basic Tutorials • Intermediate Tutorials • Advanced Tutorials • Content Mod Concepts |
Code Modding | Code Mods • Setting up your Development Environment |
Property Overview | Item • Entity • Block • Block Behaviors • Block Classes • Block Entities • Block Entity Behaviors • World properties |
Workflows & Infrastructure | Modding Efficiency Tips • Mod-engine compatibility • Mod Extensibility • VS Engine |
Additional Resources | Community Resources • Modding API Updates • Programming Languages • List of server commands • List of client commands • Client startup parameters • Server startup parameters Example Mods • API Docs • GitHub Repository |