Skip to content

Instantly share code, notes, and snippets.

@msg555
Last active August 1, 2017 20:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save msg555/ee38184ca33801e6ef163ca6699f3f55 to your computer and use it in GitHub Desktop.
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