Skip to content

Commit 56fb7a4

Browse files
committed
Fix: Stop strafing script when leaving selection area
Calling 'stop()' when leaving the strafe selection area ensures that the script properly terminates, cleaning up all keybinds and removing the tick listener. This resolves an issue where inputs would not register correctly after leaving the area due to the script continuously releasing managed keys.
1 parent c7e6bef commit 56fb7a4

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

src/skyblock/main.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,45 @@ class StrafingScript {
272272
}
273273
}
274274

275+
private isOutOfBounds(pos: any): boolean {
276+
const _1 = this.config.position['1'];
277+
const _2 = this.config.position['2'];
278+
279+
if (isNaN(_1.x) || isNaN(_2.x)) return false;
280+
281+
const x = Math.floor(pos.getX());
282+
const y = Math.floor(pos.getY());
283+
const z = Math.floor(pos.getZ());
284+
285+
const minX = Math.min(_1.x, _2.x);
286+
const maxX = Math.max(_1.x, _2.x);
287+
const minY = Math.min(_1.y, _2.y);
288+
const maxY = Math.max(_1.y, _2.y);
289+
const minZ = Math.min(_1.z, _2.z);
290+
const maxZ = Math.max(_1.z, _2.z);
291+
292+
return x < minX || x > maxX || y < minY || y > maxY || z < minZ || z > maxZ;
293+
}
294+
275295
private tick() {
276296
try {
277-
if (!this.isRunning || Hud.getOpenScreen()) {
278-
if (Hud.getOpenScreen()) {
279-
this.cleanupKeys();
280-
}
281-
return;
282-
}
297+
if (!this.isRunning) return;
283298

284299
const player = Player.getPlayer();
285300
if (!player) return;
286301

287302
const pPos = player.getPos();
288303

304+
if (this.isOutOfBounds(pPos)) {
305+
this.stop();
306+
return;
307+
}
308+
309+
if (Hud.getOpenScreen()) {
310+
this.cleanupKeys();
311+
return;
312+
}
313+
289314
// --- Distance Tracking ---
290315
if (this.lastPos) {
291316
const dMove = Math.sqrt(
@@ -395,10 +420,13 @@ class StrafingScript {
395420
if (interact.mode === 'click') {
396421
const currentCps = interact.cps ?? this.defaultConfig.options.interact[dir].cps ?? 10;
397422
const delayMs = 1000 / currentCps;
398-
if (Date.now() - this.lastClickTime[dir] >= delayMs) {
399-
key.click();
400-
this.lastClickTime[dir] = Date.now();
423+
if (Date.now() - this.lastClickTime[dir] >= delayMs/2) {
424+
if (key.pressed) key.release();
425+
else key.hold();
401426
}
427+
// } else {
428+
// key.set(true);
429+
// }
402430
} else if (interact.mode === 'hold') {
403431
key.set(true);
404432
} else {

0 commit comments

Comments
 (0)