《饥荒联机版》三尾猫鞭右键抽打队友模组代码

ChatGPT4o 使用 ChatGPT 4o 回答

问题:

请用lua语言帮我编写一个游戏模组,该游戏是《饥荒联机版》,游戏英文名是《Don't Starve Together》,游戏内有一个道具名叫三尾猫鞭,游戏代码是whip,我想让三尾猫鞭用鼠标右键可以对游戏内其他玩家使用,达到抽打队友的效果,但不会扣除队友的生命值,游戏内只是加载队友被攻击的动画。同时,玩家使用三尾猫鞭抽打队友后,会随机说出一句台词,台词内容可以自定义修改。当使用鞭子的玩家说出台词后,被鞭子抽打的玩家也会随机说出一句台词,台词内容玩家可以自定义修改。请你按照以上要求帮我编写该游戏模组。

回答:

好的,我可以帮助你编写一个《饥荒联机版》(Don't Starve Together)的模组。这个模组将允许玩家使用三尾猫鞭(whip)右键点击其他玩家,触发抽打效果并随机说出自定义台词。以下是一个基本的模组代码示例:

  1. 创建模组文件夹和文件结构:
MyWhipMod/
├── modinfo.lua
└── modmain.lua
  1. modinfo.lua 文件内容:
name = "Whip Interaction Mod"
description = "Allows players to use the whip on other players with right-click."
author = "YourName"
version = "1.0"

forumthread = ""

api_version = 10

dst_compatible = true
all_clients_require_mod = true
client_only_mod = false

icon_atlas = "modicon.xml"
icon = "modicon.tex"
  1. modmain.lua 文件内容:
local whip_prefab = "whip"

local function GetRandomLine(lines)
    return lines[math.random(#lines)]
end

local function OnWhipUsed(inst, target)
    if target and target:HasTag("player") then
        -- Trigger the attack animation on the target
        target.AnimState:PlayAnimation("hit")
        target.AnimState:PushAnimation("idle", true)

        -- Define custom lines for the attacker and the target
        local attacker_lines = {
            "Take that!",
            "Feel the sting!",
            "Whipped into shape!",
        }

        local target_lines = {
            "Ouch!",
            "Hey, watch it!",
            "That hurts!",
        }

        -- Make the attacker say a random line
        if inst.components.talker then
            inst.components.talker:Say(GetRandomLine(attacker_lines))
        end

        -- Make the target say a random line
        if target.components.talker then
            target.components.talker:Say(GetRandomLine(target_lines))
        end
    end
end

local function AddWhipRightClickAction()
    local Action = GLOBAL.Action
    local ACTIONS = GLOBAL.ACTIONS
    local ActionHandler = GLOBAL.ActionHandler

    local WHIP_PLAYER = Action({ priority = 10, rmb = true })
    WHIP_PLAYER.id = "WHIP_PLAYER"
    WHIP_PLAYER.str = "Whip"
    WHIP_PLAYER.fn = function(act)
        if act.doer and act.target and act.target:HasTag("player") then
            OnWhipUsed(act.doer, act.target)
            return true
        end
        return false
    end

    AddAction(WHIP_PLAYER)

    AddComponentAction("EQUIPPED", "whip", function(inst, doer, target, actions, right)
        if right and target:HasTag("player") then
            table.insert(actions, ACTIONS.WHIP_PLAYER)
        end
    end)

    AddStategraphActionHandler("wilson", ActionHandler(ACTIONS.WHIP_PLAYER, "doshortaction"))
    AddStategraphActionHandler("wilson_client", ActionHandler(ACTIONS.WHIP_PLAYER, "doshortaction"))
end

AddPrefabPostInit(whip_prefab, AddWhipRightClickAction)

这个模组代码实现了以下功能:

  1. modinfo.lua 中定义了模组的基本信息。
  2. modmain.lua 中定义了一个新的右键动作 WHIP_PLAYER,当玩家使用三尾猫鞭右键点击其他玩家时触发。
  3. 当鞭子被使用时,目标玩家会播放被攻击的动画,且不会扣除生命值。
  4. 使用鞭子的玩家和被鞭子抽打的玩家会随机说出自定义的台词。

你可以根据需要修改 attacker_linestarget_lines 中的台词内容。希望这个模组代码能满足你的需求!