回答
以下是使用Hamibot自动化脚本抢购泡泡玛特盲盒的步骤和示例代码:
准备工作
- 安装Hamibot
确保已安装Hamibot并授予截图权限(通过requestScreenCapture()
申请)。 - 准备按钮截图
提前保存盲盒购买按钮的截图(如“立即购买”按钮)作为模板图片,命名为buy_button.png
,并放在Hamibot脚本目录中。
脚本实现步骤
1. 申请截图权限
auto.waitFor();
if (!requestScreenCapture()) {
toastLog("未获取截图权限,请在设置中允许Hamibot截图!");
hamibot.exit();
}
2. 定义检测函数
// 检测按钮位置(示例使用findColor,需替换为实际颜色值)
function findButtonColor() {
var img = captureScreen(); // 截屏
// 假设按钮中心颜色为红色,阈值50(可调整)
var pos = images.findColor(img, "#FF0000", 50);
return pos;
}
// 或者使用图像匹配(需有按钮图片)
function findButtonImage() {
var img = captureScreen();
var template = images.read("buy_button.png"); // 替换为你的按钮图片路径
var result = images.findImage(img, template, 0.9); // 0.9为匹配度阈值
return result;
}
3. 自动点击逻辑
toast("开始抢购,检测到按钮将自动点击!");
var startTime = new Date().getTime();
var timeout = 60000; // 最长等待60秒
while (true) {
// 检测按钮(此处选择颜色或图像检测中的一种)
var pos = findButtonColor(); // 或使用findButtonImage()
if (pos && pos.x && pos.y) {
// 点击按钮(添加偏移量可能更准确)
click(pos.x, pos.y);
toast("检测到按钮,已点击!");
hamibot.exit(); // 成功后退出脚本
} else {
// 每隔0.5秒检测一次
sleep(500);
}
// 超时退出
if ((new Date().getTime() - startTime) > timeout) {
toast("超时未检测到按钮,退出脚本!");
hamibot.exit();
}
}
注意事项
-
权限问题
- 首次运行需在弹窗中选择“总是允许”截图权限。
- 安卓10及以上需将Hamibot设为前台应用(通过系统设置或脚本中手动切换)。
-
图像匹配优化
- 若用
findImage
,需确保buy_button.png
与屏幕按钮完全匹配(尺寸、位置、透明度)。 - 调整匹配阈值(如
0.9
),数值越接近1越精确。
- 若用
-
防封策略
- 可在
sleep()
中随机延时(如sleep(random(500, 1000))
)避免被识别为脚本。 - 避免在非官方渠道滥用脚本,遵守平台规则。
- 可在
完整示例代码
auto.waitFor();
if (!requestScreenCapture()) {
toastLog("未获取截图权限,请在设置中允许Hamibot截图!");
hamibot.exit();
}
toast("开始抢购,检测到按钮将自动点击!");
var startTime = new Date().getTime();
var timeout = 60000; // 最长等待时间(毫秒)
function findButton() {
var img = captureScreen();
// 方法1:颜色检测(假设按钮中心为红色)
var pos = images.findColor(img, "#FF0000", 50);
if (pos) return pos;
// 方法2:图像匹配(备用方案)
var template = images.read("buy_button.png");
var result = images.findImage(img, template, 0.9);
return result ? result : null;
}
while (true) {
var pos = findButton();
if (pos && pos.x && pos.y) {
click(pos.x, pos.y);
toast("检测到按钮,已点击!");
hamibot.exit();
} else {
sleep(500); // 每隔0.5秒检测一次
}
if ((new Date().getTime() - startTime)
> 本回答由 AI 生成,内容仅供参考
ℹ️ 本回答由 AI 生成,内容仅供参考
在脚本点更多,创建脚本工单问下脚本作者