Guest User

Untitled

a guest
May 26th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. var room = HBInit({});
  2.  
  3. var playersThatReachedTheGoal = new Set();
  4.  
  5. function handleGameTick() {
  6. var players = room.getPlayerList();
  7.  
  8. for (var i = 0; i < players.length; i++) { // Iterate over all the players
  9. var player = players[i];
  10. var position = player.position;
  11. if ( position == null ) continue; // Skip players that don't have a position
  12. if ( playersThatReachedTheGoal.has(player.id) ) continue; // Skip players that already reached the goal
  13.  
  14. if ( position.y > 80 ) {
  15. room.sendChat(player.name + " reached the goal");
  16. playersThatReachedTheGoal.add(player.id); // Mark the player as having reached the goal so that it's no longer notified later on.
  17. }
  18. }
  19. }
  20.  
  21. function handleGameStart() {
  22. playersThatReachedTheGoal.clear(); // Reset the set of players that reached the goal
  23. }
  24.  
  25. room.onGameTick = handleGameTick;
  26. room.onGameStart = handleGameStart;
Add Comment
Please, Sign In to add comment