Jump to content

Recommended Posts

Posted

English:
"How can I make players perform custom animations?
I added a new animation called 's1' to the file at 'D:\Vintagestory\assets\game\shapes\entity\seraph-faceless.json'. I can make NPCs perform the 's1' animation using the command '/npc exec playanim s1 1', but I cannot make players perform the 's1' animation using '/emote s1'. How can I make players perform the 's1' animation?
I asked ChatGPT about this and received a mod code, but ChatGPT modified it more than 10 times without successfully getting it to run. Below is the mod code."

原文:
请问如何让玩家做出自定义动作?
我在“D:\Vintagestory\assets\game\shapes\entity\seraph-faceless.json”这个文件中添加了新动作“s1”,我可以用“/npc exec playanim s1 1”指令让NPC做出“s1”动作。但是不能用“/emote s1”让玩家做出“s1”动作。请问,如何让玩家做出“s1”动作?我想ChatGPT询问,得到了一个mod代码,这个代码ChatGPT修改了10多次也没有成功运行。下面是mod代码。

——————————————————————————————————————————————————————

using System;
using Vintagestory.API.Common;
using Vintagestory.API.Server;
using Vintagestory.API.Client;
using Vintagestory.API.MathTools;
using Vintagestory.GameContent;

public class ZengruiModSystem : ModSystem
{
    // 服务端 API(可空)
    private ICoreServerAPI? sapi;

    // 网络消息频道标识
    private const string EmoteChannel = "Zengrui.Emote";

    public override void StartServerSide(ICoreServerAPI api)
    {
        base.StartServerSide(api);
        sapi = api;

        // ==================================================
        // 注册网络频道(字符串类型消息)
        var channel = api.Network.RegisterChannel(EmoteChannel)
            .RegisterMessageType<string>();

        // ==================================================
        // /emotes1 指令
        api.ChatCommands
           .Create("emotes1")
           .WithDescription("播放自定义动作 s1")
           .HandleWith(args =>
           {
               if (args.Caller.Player is IServerPlayer sPlayer)
               {
                   // 向客户端发送动画名
                   channel.SendPacket(sPlayer, "s1");
                   return TextCommandResult.Success("请求播放动作 s1");
               }

               return TextCommandResult.Error("未找到服务器端玩家");
           });
    }

    public override void StartClientSide(ICoreClientAPI capi)
    {
        base.StartClientSide(capi);

        // ==================================================
        // 注册客户端网络消息处理
        var channel = capi.Network.GetChannel(EmoteChannel);
        channel.SetMessageHandler<string>((animCode) =>
        {
            var entity = capi.World.Player.Entity;
            if (entity?.AnimManager != null)
            {
                entity.AnimManager.StartAnimation(animCode);
            }
        });
    }
}

  • 3 weeks later...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.