Skip to content

Instantly share code, notes, and snippets.

@Riemnand
Last active June 25, 2024 14:41
Show Gist options
  • Save Riemnand/ddb24022401e6bc259f298e8e5f41a27 to your computer and use it in GitHub Desktop.
Save Riemnand/ddb24022401e6bc259f298e8e5f41a27 to your computer and use it in GitHub Desktop.
Robo's istrolid script that adds a hotkey to use the jump engine and operate blimps for easy.
/*
Press Q* to make the selected ships jump towards your cursor.
Press shift + Q* to make the selected ships jump and move back.
Hold alt to make selected ships automatically jump and move back after firing all its turrets.
* --> This hotkey can be changed in the settings.
Made by RoboDrone @riemnand.
I made this script a long time ago. The code here is a very dirty mess.
But it works, and since the game is dead now, I'm too lazy to make it better.
In the case of a too bad internet connection, the script may work poorly,
since I did not teach it to take into account the delay of the Internet connection,
but used some static value for this, which was optimal for me personally.
*/
//jump hotkey script:
(function() {
if (window.jumpHotkeyScriptLoaded) {
return console.error("Error loading Robo's jump hotkey script: another one is already loaded.")
} else {
window.jumpHotkeyScriptLoaded = true
}
try {
window.DEFAULT_SETTINGS.JumpKey = {
keys: [{
which: 81 //q
}, null]
};
var jumpScriptDelay = false;
var blimpJump = window.blimpJump || {
onkeydown: ControlsMode.prototype.onkeydown
};
var unHold = function() {
var hold = false;
commander.selection.forEach(unit => {
if (unit.holdPosition != undefined) {
if ((!unit.holdPosition && holdWorking) || (unit.holdPosition && !holdWorking)) {
hold = true;
}
}
})
if (hold) {
return network.send("holdPositionOrder");
}
return;
};
function back(unit) {
unHold();
if (unit._rot > 0) {
return unit._rot - Math.PI
} else {
return unit._rot + Math.PI
}
};
function findPoint(unit, pos = undefined, bias = 1, angle = undefined) {
if (angle === undefined) {
angle = back(unit) - (Math.PI / 2);
};
let unitJump = unit.jump;
if (unitJump === 0) {
unitJump = 200
};
var distance = (unitJump - 10) * bias;
if (pos === undefined) {
pos = unit.pos;
};
var velMultiplier = 3;
if (!sim.local) {
velMultiplier = 7
}
var pointX = pos[0] + unit.vel[0] * velMultiplier + distance * Math.cos(angle)
var pointY = pos[1] + unit.vel[1] * velMultiplier + distance * Math.sin(angle)
return [pointX, pointY]
};
function jump() {
var formation = [];
// unHold();
allyUnits().forEach(element => formation.push(findPoint(element)));
battleMode.moveOrder(formation, false);
};
function allyUnits() {
let selection = commander.selection;
let allyUnits = [];
selection.forEach(unit => {
if (unit.owner === commander.number) {
allyUnits.push(unit)
}
})
return allyUnits;
}
function findShooted(units = commander.selection) {
let reloading = []
units.forEach(unit => {
let weaponsReloading = 0;
unit.weapons.forEach(weapon => {
if (!weapon.working) {
weaponsReloading++
}
})
if (weaponsReloading == unit.weapons.length) {
reloading.push(unit);
}
})
return reloading;
};
var ordered = {};
function giveOrder(units, func) {
let unitsTemp = [];
units.forEach(unit => {
if (ordered[unit.id] == undefined) {
unitsTemp.push(unit)
}
})
units = unitsTemp;
if (units.length == 0 || typeof(func) != "function") {
return
};
let lastSelection = commander.selection;
battleMode.selectUnits(units);
func();
units.forEach(unit => {
ordered[unit.id] = true;
setTimeout(function() {
delete ordered[unit.id];
}, 3000)
})
setTimeout(function() {
battleMode.selectUnits(lastSelection);
}, 200)
}
function jumpAndMoveBack() {
var formation = [];
let commanderUnits = allyUnits();
commanderUnits.forEach(element => formation.push(findPoint(element)));
unHold();
battleMode.moveOrder(formation, false);
var formation2 = [];
for (let i = 0; i != commander.selection.length; i++) {
formation2.push(findPoint(commanderUnits[i], formation[i], 6))
};
setTimeout(function() {
battleMode.moveOrder(formation2, true);
}, 200)
};
function newAngleBetween(a, b) {
return Math.atan2(a[1] - b[1], a[0] - b[0]);
};
function jumpToCursor() {
var formation = [];
let commanderUnits = allyUnits();
commanderUnits.forEach(element => formation.push(findPoint(element, undefined, 1, newAngleBetween(v2.create(battleMode.mouse), element.pos))));
unHold();
battleMode.moveOrder(formation, false);
var formation2 = [];
for (let i = 0; i != commander.selection.length; i++) {
formation2.push(findPoint(commanderUnits[i], formation[i], 4, newAngleBetween(v2.create(battleMode.mouse), commander.selection[i].pos)))
};
setTimeout(function() {
battleMode.moveOrder(formation2, true);
}, 200)
};
var timer;
var holdWorking = false;
var working = false;
var timerForWorking;
var timer2;
var managedBlimps = {};
ControlsMode.prototype.onkeydown = function(e) {
if (settings.key(e, "JumpKey") && !jumpScriptDelay) {
jumpScriptDelay = true;
setTimeout(function() {
return jumpScriptDelay = false;
}, 1000)
if (e.shiftKey) {
jumpAndMoveBack();
} else {
jumpToCursor();
}
};
if (e.code == "KeyZ") {
clearTimeout(timer);
holdWorking = true;
timer = setTimeout(function() {
holdWorking = false
}, 250);
};
if (e.altKey) {
commander.selection.forEach(unit => {
managedBlimps[unit.id] = unit
});
clearTimeout(timer2);
timer2 = setTimeout(function() {
managedBlimps = {};
}, 500);
}
return blimpJump.onkeydown.call(this, e);
}
try {
ui_origin5555 = window.body;
} catch (e) {}
window.body = e => {
if (Object.keys(managedBlimps).length > 0) {
let shooted = findShooted(managedBlimps.values);
if (shooted.length > 0) {
giveOrder(shooted, jumpAndMoveBack)
};
}
return ui_origin5555.call(this, e);
};
} catch (err) {
console.error("Error in Robo's jump hotkey script:\n" + err)
}
}).call(this)
//end.
@Riemnand
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment