Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var room = HBInit({});
- var playersThatReachedTheGoal = new Set();
- function handleGameTick() {
- var players = room.getPlayerList();
- for (var i = 0; i < players.length; i++) { // Iterate over all the players
- var player = players[i];
- var position = player.position;
- if ( position == null ) continue; // Skip players that don't have a position
- if ( playersThatReachedTheGoal.has(player.id) ) continue; // Skip players that already reached the goal
- if ( position.y > 80 ) {
- room.sendChat(player.name + " reached the goal");
- playersThatReachedTheGoal.add(player.id); // Mark the player as having reached the goal so that it's no longer notified later on.
- }
- }
- }
- function handleGameStart() {
- playersThatReachedTheGoal.clear(); // Reset the set of players that reached the goal
- }
- room.onGameTick = handleGameTick;
- room.onGameStart = handleGameStart;
Add Comment
Please, Sign In to add comment