Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Restore air charges when player collects dust
const int MAX_PLAYERS = 4;
class script {
/* We don't actually use the scene object in this script, but most will. */
scene@ g;
/* Keep track of how much dust we had in the last frame. */
array<int> dust_last;
/* Keep track of how much dust we had when the last checkpoint was saved. */
array<int> dust_checkpoint;
script() {
@g = get_scene();
/* Initialize each player to have collected 0 dust last frame. */
for (int i = 0; i < MAX_PLAYERS; i++) {
dust_last.insertLast(0);
dust_checkpoint.insertLast(0);
}
}
void step(int entities) {
for (int i = 0; i < MAX_PLAYERS; i++) {
/* Try to get a 'dustman' object handle for each player. */
entity@ e = controller_entity(i);
if (@e == null) {
continue;
}
dustman@ dm = e.as_dustman();
if (@dm == null) {
continue;
}
/* If the player exists check its total filth and see how it compares to
* last frame. If it's increased set their 'dash' (aircharges) back to
* their 'dash_max' (max aircharges). */
int dust_cur = dm.total_filth();
if (dust_cur > dust_last[i]) {
puts("Restoring Air Charges");
dm.dash(dm.dash_max());
}
/* Note the last seen dust count for thsi player. */
dust_last[i] = dust_cur;
}
}
void checkpoint_save() {
/* Save the current dust counts when the checkpoint is saved. */
dust_checkpoint = dust_last;
}
void checkpoint_load() {
/* Restore the saved dust counts when a checkpoint is loaded. */
dust_last = dust_checkpoint;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment