一键玩IDE函数脚本函数LUA语言

一键玩IDE函数脚本函数LUA语言

一键玩IDE函数-拾忆资源
一键玩IDE函数脚本函数LUA语言
此内容为付费阅读,请付费后查看
9.9
立即购买
您当前未登录!建议登陆后购买,可保存购买订单
付费阅读
已售 368

常用函数

持续拖动

function 持续拖动(x1, y1, x2, y2, time, 是否抬起,偏移)
    local sj = rnd(0, 偏移)
    touchDown(0, x1 + sj, y1 + sj)
    sleep(20)
    touchMove(0, x2 + sj, y2 + sj, time)
    if 是否抬起 == true then
        touchUp(0)
    end 
end

单击

function 单击(x,y,正负偏移)
    local 随机 = rnd(0-正负偏移,正负偏移)
    tap(x+随机,y+随机)
end

字符分割

--字符分组函数(szFullString=要分组的字符串,szSeparator=用什么字符分割)
function 转数组(szFullString, szSeparator)
    local nFindStartIndex = 1
    local nSplitIndex = 1
    local nSplitArray = {}
    if szFullString == nil or szSeparator == nil then
        return {}
    end
    while true do
        local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
        if not nFindLastIndex then
            nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
            break
        end
        nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
        nFindStartIndex = nFindLastIndex + string.len(szSeparator)
        nSplitIndex = nSplitIndex + 1
    end
    return nSplitArray
end

脚本运行时间获取

function 运行时间()--将运行时间转为天,时,分
    local 运行 = tickCount()
    local days = math.floor(运行 / (1000 * 60 * 60 * 24))
    local hours = math.floor(运行 % (1000 * 60 * 60 * 24) / (1000 * 60 * 60))
    local minutes = math.floor(运行 % (1000 * 60 * 60) / (1000 * 60))
    return days, hours, minutes
end

检查游戏是否在前台

function 前台检测(bm)
    local 前台act = exec("dumpsys window | grep mCurrentFocus")
    local 查找, 长度 = string.find(前台act, bm)
    if 查找 then
        return true
    else
        return false
    end
end

数组找元素

--数组中是否包含指定元素
function 数组找元素(原数组, 值)
    for i = 1, #原数组 do
        if 原数组[i] == 值 then
            return true
        end
    end
    return false
end

找字函数

--【部分1】存放找字参数的数组
--全局数组存放要找的字的参数,师门和师门2为一个字在不同的范围
全局找字 = {
师门 = {194,144,317,198,"师门","49454F-202020",0.8,0}
,师门2 = { 511, 125, 325, 45,"师门","49454F-202020",0.8,0}
,帮派 = { 32, 445, 212, 421, "帮派", "F9F5F3-303030", 0.8, 0 }
}

--【部分2】函数封装
--找字封装:支持找字后点击;偏移点击;偏移范围点击;找字成功返回所在坐标
function 字库找字(数组, 是否点击, 点击偏移x, 点击偏移y, 偏移范围)
    --判断参数为空,设置默认值
    if 是否点击 == nil then
        是否点击 = false
    end
    if 点击偏移x == nil then
        点击偏移x = 0
    end
    if 点击偏移y == nil then
        点击偏移y = 0
    end
    if 偏移范围 == nil then
        偏移范围 = 0
    end
    --找字函数拿参数
    local x = -1 y = -1 ret = -1
    ret, x, y = findStr(数组[1], 数组[2], 数组[3], 数组[4], 数组[5], 数组[6], 数组[7], 数组[8])
    if x ~= -1 and y ~= -1 then
        print("找字成功:【" .. 数组[5] .. "】")
        if 是否点击 ~= false then
            --偏移点击以及偏移范围点击
            local 偏移xx = rnd(0, 偏移范围)
            local 偏移yy = rnd(0, 偏移范围)
            tap(x + 点击偏移x + 偏移xx, y + 点击偏移y + 偏移yy)
            return true, x, y
        else
            return true, x, y
        end
    else
        print("找字失败:【" .. 数组[5] .. "】")
        return false
    end
end


--【部分3:找字的使用示例】
setDict(0,"教程.txt")--字库初始化
useDict(0)--使用字库

--找字拿到找字结果和字的xy坐标示例:
local ret, x, y = 字库找字(全局找字.师门,true,367,92)

--找字并偏移点击示例:
字库找字(全局找字.师门,true,367,92)

--找字点击字示例:
字库找字(全局找字.师门,true)

--判断找字成功示例:
if  字库找字(全局找字.师门) then
    print("找字成功")
end


文件函数

读取文件内容

function 读文件内容(路径)
    -- 打开文件,"r" 表示只读模式
    local file = io.open(路径, "r"
)
    if not file then
        -- 文件不存在或无法打开
        return "-1"
    end
    -- 读取文件内容
    local content = file:read("*all"
)

    -- 关闭文件
    file:
close
()

    -- 打印文件内容
    --print("文件内容"..content)
    return
 content
end

写入文件内容

function 写入文件(路径,内容,是否续写)--1需要续写,0重写
    -- 打开文件用于写入
    local file, err = 0,0
    if 是否续写 == 0 then
        file, err = io.open(路径, "w")
    else
        file, err = io.open(路径, "a")
    end

    -- 检查是否成功打开文件
    if not file then
        print("无法打开文件: " .. tostring(err))
        return
    end

    -- 写入文本到文件
    file:write(内容)

    -- 关闭文件
    file:close()
end

提取指定行文本

function 读取一行文本(file_path, line_number)
    local file = io.open(file_path, "r")
    if not file then return nil end
    local current_line = 1
    local line
    while true do
        line = file:read("*line")
        if not line then break end
        if current_line == line_number then
            file:close()
            return line
        end
        current_line = current_line + 1
    end
    file:close()
    return nil -- 如果指定的行号不存在,则返回nil
end

复制文件

function 复制文件(source_path, destination_path)
    local source_file = io.open(source_path, "rb") -- 打开源文件以二进制方式读取
    if not source_file then
        error("Unable to open source file " .. source_path)
    end
    local content = source_file:read("*a") -- 读取整个文件内容
    source_file:close() -- 关闭源文件
    local destination_file = io.open(destination_path, "wb") -- 打开目标文件以二进制方式写入
    if not destination_file then
        error("Unable to open destination file " .. destination_path)
    end
    destination_file:write(content) -- 写入内容
    destination_file:close() -- 关闭目标文件
end

获取文本行数

function 获取文件行数(file_path)
    local file = io.open(file_path, "r")
    if file then
        file:close()
    else
        return 0 --无此文件返回0行
    end
    local count = 0
    for line in io.lines(file_path) do
        count = count + 1
    end
    return count
end

获取文件对象值

function 获取文件对象值(path, txt) --文件路径,对象名
    local 行数 = 获取文件行数(path)
    for i = 1, 行数, 1 do
        local 内容 = 读取一行文本(path, i)
        local pos, poss = string.find(内容, txt .. "=")
        if pos == 1 then
            -- 获取该字符后的所有字符
            local substr = string.sub(内容, poss + 1)
            return substr
        end
    end
    return nil -- 如果不存在,则返回nil
end

写入文件对象值

function 写入文件对象值(path, txt, 对象值) --文件路径,对象名,对象值
    local 行数 = 获取文件行数(path)
    local 表 = {}
    local 修改 = 0
    for i = 1, 行数, 1 do
        local 内容 = 读取一行文本(path, i)
        local pos, poss = string.find(内容, txt .. "=")
        if pos == 1 then
            -- 获取该字符后的所有字符
            local substr = string.sub(内容, poss + 1)
            表[i] = txt .. "=" .. 对象值
            修改 = 1
        else
            表[i] = 内容
        end
    end
    if 修改 == 0 then
        表[#表 + 1] = txt .. "=" .. 对象值
    end
    local file = io.open(path, "w")
    file:write("") -- 写入空字符串
    if file then
        for i, v in ipairs(表) do
            if i == #表 then -- 如果是最后一个元素,则不再添加换行符
                file:write(v)
            else
                file:write(v .. "\n") -- 添加换行符
            end
        end
        file:close()
    else
        error("无法打开文件 " .. path)
    end
    return nil
end
© 版权声明
THE END
喜欢就支持一下吧
点赞1523 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容