Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
const int MAX_PLAYERS = 4;
class script {
scene@ g;
array<controllable@> players;
script() {
@g = get_scene();
players.resize(MAX_PLAYERS);
}
void on_player_hit(controllable@ pl, controllable@ hit,
hitbox@ hb, int player_num) {
puts("PLAYER HIT " + player_num + " DAMAGE = " + hb.damage());
}
void on_player_hurt(controllable@ pl, controllable@ hitter,
hitbox@ hb, int player_num) {
puts("PLAYER HURT " + player_num + " DAMAGE = " + hb.damage());
}
void step(int entities) {
for (int i = 0; i < MAX_PLAYERS; i++) {
if (@players[i] == null) {
entity@ e = controller_entity(i);
if (@e != null) {
@players[i] = e.as_controllable();
if (@players[i] != null) {
players[i].add_on_hit_callback("on_player_hit", i);
players[i].add_on_hurt_callback("on_player_hurt", i);
}
}
}
}
}
void checkpoint_load() {
for (int i = 0; i < MAX_PLAYERS; i++) {
@players[i] = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment