这段Lua代码是一个游戏mod的一部分,用于添加一些与汽车维修和尸体处理相关的功能。下面是代码主要部分的注释:

--定义一个本地函数jdjy_repaircar,用于修理车辆 local function jdjy_repaircar(playerObj,vehiclez) --发送客户端命令,修理车辆 sendClientCommand(playerObj, "vehicle", "repair", { vehicle = vehiclez:getId() }) --从玩家背包中移除一个超级修车工具 playerObj:getInventory():Remove("superxiuchegongjv") --创建一个车辆钥匙 local key = vehiclez:createVehicleKey() --将车辆钥匙添加到玩家背包中 playerObj:getInventory():AddItem(key) end

--定义一个本地函数jdjy_qiaosuo,用于使用撬锁工具 local function jdjy_qiaosuo(playerObj,door,square) --如果有方块,并且可以走到方块上 if square and luautils.walkAdj(playerObj, square) then --添加一个撬锁行动 ISTimedActionQueue.add(ISqiaosuogongjv:new(playerObj, door, 100)) end end

--定义一个本地函数Context_chuliCorpse,用于处理尸体 local function Context_chuliCorpse(player, context, worldobjects, test) --获取点击的方块 local square = clickedSquare --获取玩家对象和背包 local playerObj = getSpecificPlayer(player) local playerInv = playerObj:getInventory() --如果玩家正在睡觉,则退出函数 if playerObj:isAsleep() then return end local asquare local bodys local bodyss = {} local bodynum =0 local alldeadbody = {}

--定义一个函数addTooltip,用于添加提示信息
local addTooltip = function(option, spriteName)
	local tooltip = ISToolTip:new();
	tooltip:initialise();
	tooltip:setName("");
	tooltip:setTexture(spriteName);
	option.toolTip = tooltip
end

--如果玩家有超级修车工具,则添加一个修车选项
if playerObj:getInventory():contains("superxiuchegongjv") then
    local vehiclez = square:getVehicleContainer()
    if vehiclez then
        local submenuv = context:addOption(getText("IGUI_chaojixiuche"), playerObj, jdjy_repaircar,vehiclez)
    end
end

--如果玩家有拆解工具,则添加一个拆解选项
if playerObj:getInventory():contains("jianzhukuoronggongjv") then
    local copyOption = context:addOption(getText("IGUI_kuorong"), worldobjects)
    local copySubMenu = context:getNew(context)
    context:addSubMenu(copyOption, copySubMenu)
    local opt = nil
    for _, obj in pairs(worldobjects) do
        if obj:getSprite() ~= nil and obj:getSprite():getName() ~= nil then
            for i=1,obj:getContainerCount() do
                local con = obj:getContainerByIndex(i-1)
                if con  then
                    opt = copySubMenu:addOption(getText("IGUI_kuorong"), con, setTileCursor2, playerObj,obj)
                    addTooltip(opt, obj:getSprite():getName())
                end
            end
        end
    end
end

--查找周围的尸体
for i = -3,3 do
    for k = -3,3 do
        asquare = getCell():getGridSquare(square:getX()+i,square:getY()+k,square:getZ())
        if asquare then
            bodys = asquare:getDeadBodys()
        end
        if bodys then
            for i =1 ,bodys:size() do
                table.insert(bodyss,bodys:get(i-1))
                bodynum = bodynum +1
            end    
        end 
    end
end

--如果有尸体,并且玩家有刀,则添加一个拆解尸体选项
if #bodyss >= 1 then
    if (playerInv:containsTypeRecurse("BreadKnife") or playerInv:containsTypeRecurse("ButterKnife") or playerInv:containsTypeRecurse("HuntingKnife") or playerInv:containsTypeRecurse("KitchenKnife") or playerInv:containsTypeRecurse("zombieknife")) and playerInv:getItemCount("Base.CorpseMale") == 0 then
        if test == true then return true end
        local submenu2 = context:addOption(getText("ContextMenu_dessectcorpse"), worldobjects, nil)
        local subMenu3 = ISContextMenu:getNew(context)
        context:addSubMenu(submenu2, subMenu3)
        subMenu3:addOption(getText("ContextMenu_dessectall"), worldobjects, chulicorseaction, player , bodyss)
        body = IsoObjectPicker.Instance:PickCorpse(square:getX(), square:getY()) or body
        if body then
            subMenu3:addOption(getText("ContextMenu_dessectone"), worldobjects, chulicorseactionone, player , body)
        end
    end
end

end

--添加一个事件监听器,在右键点击物品时触发Context_chuliCorpse函数 Events.OnPreFillWorldObjectContextMenu.Add(Context_chuliCorpse


原文地址: https://www.cveoy.top/t/topic/dxKk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录