正式服时光 由老胡统计
怀旧服时光 由老胡统计
cn
老胡的魔兽资料库

老胡聊聊天@bilibili/抖音

这里用于分享一些宏命令、WA,如果大家觉得有用,欢迎关注老胡。

未经老胡许可,请勿转载,想要加粉丝群的点这里

魔兽世界拍卖行收货插件--chatgpt写的


分区:插件     更新时间:2024-08-08     原文地址:http://wowdata.top/blog/18


必须要说一下,这个代码只是用来学习探讨,直接放到游戏里面,是不能运行的,需要改一改。

代码讲解看这个视频: https://www.bilibili.com/video/BV1824y1u7Wm

宏:

/run BuyItems("黑莲花", 20)
Lua代码
-- 定义一个全局函数BuyItems
function BuyItems(itemName, itemQuantity)
    -- 获取总共购买的数量
    local totalCount = 0

    -- 循环搜索拍卖行
    local function searchAuction(itemName, page)
        local numBatchAuctions = GetNumAuctionItems("list")
        for i = 1, numBatchAuctions do
            local itemNameAuction, _, itemCountAuction, _, _, _, _, _, buyoutPrice, _, _, _, _, _, _, _ = GetAuctionItemInfo("list", i)
            if itemNameAuction and string.find(itemNameAuction, itemName) then
                local canBuyCount = math.min(itemCountAuction, itemQuantity - totalCount)
                PlaceAuctionBid("list", i, buyoutPrice, canBuyCount)
                totalCount = totalCount + canBuyCount
            end
        end
        if totalCount < itemQuantity and numBatchAuctions == 50 and page < 10 then
            C_Timer.After(1, function() QueryAuctionItems(itemName, nil, nil, 0, 0, 0, page + 1, nil, nil) end)
        else
            print("共收购了" .. totalCount .. "件" .. itemName .. "。")
        end
    end

    -- 循环打开拍卖行窗口并搜索物品---这段老胡认为是无用的
    local function openAuction()
        if not AuctionFrame:IsVisible() then
            ShowUIPanel(AuctionFrame)
        end
        if AuctionFrameBrowse:IsVisible() then
            SearchBoxText:SetText(itemName)
            AuctionFrameBrowse_Search()
            searchAuction(itemName, 0)
        else
            C_Timer.After(1, openAuction)
        end
    end

    -- 循环打开拍卖行窗口并搜索物品
    openAuction()

    -- 循环搜索背包和行囊并使用物品
    for bag = 0, 4 do
        for slot = 1, GetContainerNumSlots(bag) do
            local name = GetContainerItemLink(bag, slot)
            if name and string.find(name, itemName) then
                local _, itemCount = GetContainerItemInfo(bag, slot)
                if totalCount < itemQuantity then
                    if (totalCount + itemCount) <= itemQuantity then
                        totalCount = totalCount + itemCount
                        UseContainerItem(bag, slot)
                    else
                        local remaining = itemQuantity - totalCount
                        totalCount = totalCount + remaining
                        UseContainerItem(bag, slot, remaining)
                    end
                end
            end
        end
    end
end

更多相关文章