我一直在寻找这样的东西,但我找不到任何可以帮助我的东西 我试图制作一个小机器人,在游戏中为我按e。我有一个如下所示的菜单:https://i.stack.imgur.com/WhV5A.png。现在我遇到的问题是保存数据,所以如果我将它从OFF更改为ON并刷新网站然后它会回到OFF并且我尝试了一些东西来存储数据但是所有这些都失败了。
代码:
我试图保存的值是mbot,sbot,zbot
// ZMIENNE //
var mbot="OFF";
var sbot="OFF";
var zbot="OFF";
var zabitem=0;
setInterval(function() {
mbot=$("#atakbot").val();
sbot=$("#strzalabot").val();
zbot=$("#zlotobot").val();
}, 1000);
setInterval( function() {
if (mbot === "ON") {
for(var i in g.npc){
if ((Math.abs(hero.rx - g.npc[i].x) <= 1 && Math.abs(hero.ry - g.npc[i].y) <= 1) && (g.npc[i].type == 2 || g.npc[i].type == 3)){
_g("fight&a=attack&id=-"+i);
$("#autobattleButton").remove();
setTimeout('_g("fight&a=f");',1000);
zabitem+=1;
break;
}
}}
}, 1000);
setInterval(function() {
if (mbot === "ON") {
$("#a_ok").click();
}
}, 10000);
setInterval( function() {
if (sbot === "ON") {
var SOK = false;
var OK2=1;
var Sitem = false;
if (OK2===1) {
SOK = false;
for(var i in g.item){
Sitem = $("#item"+i);
if(g.item[i].cl == 21 && Sitem.css("top") == "183px" && Sitem.css("left") == "92px"){
var Sstat = g.item[i].stat;
var Sname = g.item[i].name;
var Sid = g.item[i].id;
SOK = true;
break;
}
}
if(SOK){
var SnumAmmo = Sstat.indexOf("ammo");
var Sammo = 51;
if(SnumAmmo != -1){
Sammo = Sstat.slice(SnumAmmo+5,SnumAmmo+9);
Sammo = parseInt(Sammo);
}
if(Sammo < 50){
for(var i in g.item){
if(Sname == g.item[i].name && Sid != g.item[i].id){
_g("moveitem&st=1&id="+g.item[i].id);
message("<font color='#00CC99'><b><center>Strzaly zmienione</center></b></font>");
break;
}
}
}
}
}
}
}, 1000);
setInterval(function () {
if (zbot === "1") {
for (k in g.item) if ((g.item[k].loc=="g") && (g.item[k].stat.search("gold")>-1)) _g("moveitem&st=1&id=" + k);
}
}, 1000);
编辑1:解决方案就是这个
$(function() {
$('#atakbot').change(function() {
localStorage.setItem('atakbot', this.value);
});
if(localStorage.getItem('atakbot')){
$('#atakbot').val(localStorage.getItem('atakbot'));
}
});
$(function() {
$('#strzalabot').change(function() {
localStorage.setItem('strzalabot', this.value);
});
if(localStorage.getItem('strzalabot')){
$('#strzalabot').val(localStorage.getItem('strzalabot'));
}
});
$(function() {
$('#zlotobot').change(function() {
localStorage.setItem('zlotobot', this.value);
});
if(localStorage.getItem('zlotobot')){
$('#zlotobot').val(localStorage.getItem('zlotobot'));
}
});
答案 0 :(得分:0)
获取时,立即获得后备值,如:
function do_git {
cmd=$1
shift
extra=""
if [ "$cmd" == "log" ]; then
extra="--graph"
fi
"`which git`" "$cmd" "$extra" "$@"
}
表示使用var mbot = localStorage.mbot || "OFF";
或回退到localStorage.mbot
设置也很简单:
"OFF"
我已经看到你让随机$('#atakbot').on("change", function() {
mbot = localStorage.mbot = this.value;
});
在你的代码中无用地运行了。即使每1000毫秒运行一次,这不是性能杀手,但使用事件的好习惯。