-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathZoneCheck.js
More file actions
34 lines (29 loc) · 1.29 KB
/
ZoneCheck.js
File metadata and controls
34 lines (29 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var zone = {MinX: -370, MaxX: 370, MinY: -170, MaxY: 170};
var playerList = {};
var room = HBInit({ roomName: "Zone Check", noPlayer: true, public: true, maxPlayers: 2 });
function checkIfPlayerInZone(player){
return player != null && player.position != null && (zone.MinX <= player.position.x && player.position.x <= zone.MaxX) && (zone.MinY <= player.position.y && player.position.y <= zone.MaxY);
}
function warnIfPlayerInZone(){
var players = room.getPlayerList().filter(p => room.getPlayerDiscProperties(p.id) != null);
players.forEach(p => {
if(checkIfPlayerInZone(p) == true){
if(playerList[p.name].isInZoneWarning == false){
room.sendAnnouncement(`You are inside the zone!`,p.id,0xFFFFFF,"bold",2);
playerList[p.name].isInZoneWarning = true;
}
}
else{
if(playerList[p.name].isInZoneWarning == true){
room.sendAnnouncement(`You are outside the zone!`,p.id,0xFFFFFF,"bold",2);
playerList[p.name].isInZoneWarning = false;
}
}
});
}
room.onGameTick = function(){
warnIfPlayerInZone();
}
room.onPlayerJoin = function(player){
if(playerList[player.name] == undefined) playerList[player.name] = {name: player.name, isInZoneWarning: false};
}