Skip to content

Instantly share code, notes, and snippets.

@Riemnand
Last active June 25, 2024 14:40
Show Gist options
  • Save Riemnand/529c0f5a9948c2b65bc8bf7f6376e434 to your computer and use it in GitHub Desktop.
Save Riemnand/529c0f5a9948c2b65bc8bf7f6376e434 to your computer and use it in GitHub Desktop.
Robo's istrolid script, which adds the ability to see the status of reloading turrets.
/*
Script that displays the reload of turrets. Sometimes may have not critical bugs.
Press H button to start displaying the reload of selected units. You can change that hotkey in the settings.
You should load this script after the others, else it may not work, because other scripts can overwrite changes it making.
Made by RoboDrone @riemnand.
*/
//reload display script:
(function() {
if (window.reloadDisplayScriptLoaded) {
return console.error("Error loading Robo's reload display script: another one is already loaded.")
} else {
window.reloadDisplayScriptLoaded = true
}
try {
var reloadDisplay = window.reloadDisplay || {
onkeydown: ControlsMode.prototype.onkeydown
};
window.DEFAULT_SETTINGS.displayUnitReload = {
keys: [{
which: 72 //H
}, null]
};
var reloadDisplayArray = {};
Turret.prototype.clientTick = function() {
var ditance, ref, target, th;
if (!sim.local) {
if (this.reload > 0) {
this.reload -= 1;
}
if (!sim.local) {
if (this.workedBefore === undefined) {
this.workedBefore = false;
}
if (this.working) {
this.workedBefore = true;
this.reload = 0;
} else if (!this.working && this.workedBefore) {
this.reload = this.reloadTime;
this.workedBefore = false;
}
}
}
target = intp.things[this.targetId];
if (target) {
ref = this.aim(target), th = ref[0], ditance = ref[1];
this._rot = th;
} else {
return this._rot = turnAngle(this._rot, this.unit.rot, 0.075);
}
};
types.Unit.prototype.draw = (function() {
var cached_function = types.Unit.prototype.draw;
return function() {
var result = cached_function.apply(this, arguments);
if (reloadDisplayArray[this.id]) {
let unitIntp = window.intp.things[this.id];
let unit = window.sim.things[this.id];
if (unit) {
if (unit.weapons) {
unit.weapons.forEach((weapon, index) => {
if (weapon.reload > 0) {
let weaponWorldPos = unitIntp.weapons[index].worldPos;
let sizeMultiplier = (weapon.reload / weapon.reloadTime) * 2;
let colorMultiplier = (weapon.reload / weapon.reloadTime) * 255;
baseAtlas.drawSprite("parts/decals/Stripe2x2.png", [weaponWorldPos[0], weaponWorldPos[1] + 40], [1, sizeMultiplier], Math.PI / 2, [colorMultiplier, 255 - colorMultiplier, 0, 255]);
}
})
}
}
}
return result;
};
})();
var manageUnits = function(action) {
// 1 - managed, 0 - not managed
commander.selection.forEach(unit => {
reloadDisplayArray[unit.id] = action
})
}
ControlsMode.prototype.onkeydown = function(e) {
if (settings.key(e, "displayUnitReload")) {
if (!e.shiftKey) {
manageUnits(1);
} else {
manageUnits(0)
}
};
return reloadDisplay.onkeydown.call(this, e);
}
} catch (err) {
console.error("Error in Robo's reload display script:\n" + err)
}
}).call(this)
//end.
@Riemnand
Copy link
Author

example1
example2

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