-
Notifications
You must be signed in to change notification settings - Fork 0
/
SniperV1.js
190 lines (150 loc) · 12.6 KB
/
SniperV1.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
var stadiımFileText =`{
"name":"Sniper Shot V1 edited by from HaxMaps","width":450,"height":200,"spawnDistance":170,"bg":{"type":"grass","width":370,"height":170,"kickOffRadius":75,"cornerRadius":0},"vertexes":[{"x":-370,"y":170,"trait":"ballArea"},{"x":-370,"y":-170,"trait":"ballArea"},{"x":370,"y":-170,"trait":"ballArea"},{"x":0,"y":200,"trait":"kickOffBarrier"},{"x":0,"y":75,"trait":"kickOffBarrier"},{"x":0,"y":-75,"trait":"kickOffBarrier"},{"x":0,"y":-200,"trait":"kickOffBarrier"},{"x":-371,"y":-144,"trait":"goalNet","curve":-190},{"x":-375,"y":-105,"trait":"goalNet","curve":-190},{"x":370,"y":-143,"trait":"goalNet","curve":180},{"x":378,"y":-106,"trait":"goalNet","curve":180},{"x":-370,"y":-38,"trait":"goalNet","curve":-150,"bCoef":1,"color":"663366"},{"x":-374,"y":35,"trait":"goalNet","curve":-150},{"x":-375,"y":105,"trait":"goalNet","curve":-190},{"x":-371,"y":143,"trait":"goalNet","curve":-190},{"bCoef":0.1,"cMask":["red"],"trait":"goalNet","x":50,"y":-200,"curve":0,"vis":true,"color":"0000FF","_selected":"segment"},{"bCoef":0.1,"cMask":["red"],"trait":"goalNet","x":50,"y":200,"curve":0,"vis":true,"color":"0000FF","_selected":"segment"},{"x":370,"y":104,"trait":"goalNet","curve":180},{"x":370,"y":142,"trait":"goalNet","curve":180},{"x":372,"y":-37,"trait":"goalNet","curve":150},{"x":371,"y":39,"trait":"goalNet","curve":150},{"bCoef":1,"cMask":["ball"],"trait":"goalNet","x":370,"y":142,"curve":0,"vis":false},{"bCoef":1,"cMask":["ball"],"trait":"goalNet","x":370,"y":170,"curve":0,"vis":false,"color":"663366"},{"bCoef":1.5,"cMask":["ball"],"trait":"goalNet","x":-370,"y":146,"curve":0,"vis":false},{"bCoef":1.5,"cMask":["ball"],"trait":"goalNet","x":-370,"y":170,"curve":0,"vis":false},{"bCoef":1,"cMask":["ball"],"trait":"goalNet","x":-370,"y":145,"curve":0,"vis":false},{"bCoef":1,"cMask":["ball"],"trait":"goalNet","x":-370,"y":170,"curve":0,"vis":false,"color":"663366"},{"bCoef":1,"trait":"goalPost","x":-370,"y":-103,"cMask":["ball"],"curve":1},{"bCoef":1,"trait":"goalPost","x":-371,"y":-34,"cMask":["ball"],"curve":1},{"bCoef":1,"cMask":["ball"],"trait":"goalNet","x":-370,"y":-170,"color":"663366"},{"bCoef":1.5,"cMask":["ball"],"trait":"goalPost","x":-371,"y":-143},{"bCoef":1,"cMask":["ball"],"trait":"goalNet","x":-370,"y":38,"color":"663366"},{"bCoef":1,"cMask":["ball"],"trait":"goalNet","x":-370,"y":99,"color":"663366"},{"bCoef":1,"cMask":["ball"],"trait":"goalNet","x":370,"y":-170,"color":"663366"},{"bCoef":1.52,"cMask":["ball"],"trait":"goalPost","x":370,"y":-145},{"bCoef":1,"cMask":["ball"],"trait":"goalPost","x":370,"y":-104},{"bCoef":1,"cMask":["ball"],"trait":"goalPost","x":371,"y":-37},{"bCoef":0.1,"cMask":["blue"],"trait":"goalNet","x":-50,"y":-200,"curve":0,"vis":true,"color":"CC0000"},{"bCoef":0.1,"cMask":["blue"],"trait":"goalNet","x":-50,"y":200,"curve":0,"vis":true,"color":"CC0000"},{"bCoef":1,"trait":"goalNet","x":370,"y":-152,"color":"663366"},{"cMask":["ball"],"x":-370,"y":-152,"color":"663366","bCoef":1,"trait":"goalNet"},{"bCoef":1,"cMask":["ball"],"trait":"goalNet","x":-370,"y":-97,"color":"663366"},{"cMask":["ball"],"trait":"goalNet","x":370,"y":152,"bCoef":1,"color":"663366"},{"bCoef":1,"trait":"goalNet","x":370,"y":-96,"color":"663366"},{"bCoef":1,"trait":"goalNet","x":370,"y":-44,"color":"663366"},{"bCoef":1,"trait":"goalNet","x":-370,"y":150,"color":"663366"},{"bCoef":1,"trait":"goalNet","x":370,"y":49,"color":"663366"},{"bCoef":1,"trait":"goalNet","x":370,"y":96,"color":"663366"}],"segments":[{"v0":7,"v1":8,"trait":"goalNet","curve":-190},{"v0":9,"v1":10,"trait":"goalNet","curve":180},{"v0":3,"v1":4,"trait":"kickOffBarrier"},{"v0":4,"v1":5,"trait":"kickOffBarrier","curve":180,"cGroup":["blueKO"]},{"v0":4,"v1":5,"trait":"kickOffBarrier","curve":-180,"cGroup":["redKO"]},{"v0":5,"v1":6,"trait":"kickOffBarrier"},{"v0":11,"v1":12,"trait":"goalNet","curve":-150},{"v0":13,"v1":14,"trait":"goalNet","curve":-190},{"curve":0,"vis":true,"color":"0000FF","bCoef":0.1,"cMask":["red"],"trait":"goalNet","v0":15,"v1":16,"_selected":true},{"v0":17,"v1":18,"trait":"goalNet","curve":190.388857815,"x":380},{"v0":19,"v1":20,"trait":"goalNet","curve":150,"x":380},{"curve":0,"vis":false,"color":"FFCCCC","bCoef":1,"cMask":["ball"],"trait":"goalNet","v0":21,"v1":22},{"curve":0,"vis":false,"color":"FFCCCC","bCoef":1.5,"cMask":["ball"],"trait":"goalNet","v0":23,"v1":24},{"curve":0,"vis":false,"color":"FFCCCC","bCoef":1,"cMask":["ball"],"trait":"goalNet","v0":25,"v1":26},{"curve":1,"vis":false,"color":"FFCCCC","bCoef":1,"trait":"goalPost","v0":27,"v1":28,"cMask":["ball"]},{"curve":0,"vis":false,"color":"FFCCCC","bCoef":1,"cMask":["ball"],"trait":"goalPost","v0":31,"v1":32},{"curve":0,"vis":false,"color":"FFCCCC","bCoef":1,"cMask":["ball"],"trait":"goalPost","v0":35,"v1":36},{"curve":0,"vis":true,"color":"CC0000","bCoef":0.1,"cMask":["blue"],"trait":"goalNet","v0":37,"v1":38},{"vis":true,"bCoef":1,"trait":"goalNet","v0":33,"v1":39,"color":"663366"},{"vis":true,"cMask":["ball"],"v0":29,"v1":40,"color":"663366","bCoef":1,"trait":"goalNet"},{"curve":0,"vis":true,"color":"663366","bCoef":1,"cMask":["ball"],"trait":"goalNet","v0":41,"v1":11},{"curve":0,"vis":true,"color":"663366","cMask":["ball"],"trait":"goalNet","v0":42,"v1":22,"bCoef":1},{"curve":0,"vis":true,"color":"663366","bCoef":1,"trait":"goalNet","v0":31,"v1":32,"cMask":["ball"]},{"curve":0,"vis":true,"color":"663366","bCoef":1,"trait":"goalNet","v0":43,"v1":44},{"curve":0,"vis":true,"color":"663366","bCoef":1,"trait":"goalNet","v0":45,"v1":26},{"curve":0,"vis":true,"color":"663366","bCoef":1,"trait":"goalNet","v0":46,"v1":47},{"curve":0,"vis":true,"color":"663366","bCoef":1,"cMask":["ball"],"trait":"goalNet","v0":26,"v1":22},{"curve":0,"vis":true,"color":"663366","bCoef":1,"cMask":["ball"],"trait":"goalNet","v0":29,"v1":33}],"goals":[{"p0":[-370,-146],"p1":[-370,-102],"team":"red"},{"p0":[370,-110],"p1":[370,-150],"team":"blue"},{"p0":[-370,-35],"p1":[-370,35],"team":"red"},{"p0":[-370,107],"p1":[-370,147],"team":"red"},{"p0":[370,143],"p1":[370,98],"team":"blue"},{"p0":[370,35],"p1":[370,-35],"team":"blue"}],"discs":[{"pos":[-370,-105],"trait":"goalPost","color":"CC0000","bCoef":0.5},{"pos":[-370,-143],"trait":"goalPost","color":"CC0000","bCoef":0.5},{"pos":[370,-105],"trait":"goalPost","color":"0000FF","bCoef":0.5},{"pos":[370,-143],"trait":"goalPost","color":"0000FF","bCoef":0.5},{"pos":[-368,35],"trait":"goalPost","color":"CC0000","bCoef":0.5},{"pos":[-370,-35],"trait":"goalPost","color":"CC0000","bCoef":0.5},{"pos":[-370,143],"trait":"goalPost","color":"CC0000","bCoef":0.5},{"pos":[-370,105],"trait":"goalPost","color":"CC0000","bCoef":0.5},{"pos":[370,143],"trait":"goalPost","color":"0000FF","bCoef":0.5},{"pos":[370,104],"trait":"goalPost","color":"0000FF","bCoef":0.5},{"pos":[370,41],"trait":"goalPost","color":"0000FF","bCoef":0.5},{"pos":[370,-35],"trait":"goalPost","color":"0000FF","bCoef":0.5}],"planes":[{"normal":[0,-1],"dist":-170,"trait":"ballArea","bCoef":1},{"normal":[0,1],"dist":-170,"bCoef":1,"cMask":["ball"],"trait":"ballArea"},{"normal":[1,0],"dist":-450,"bCoef":0.1},{"normal":[-1,0],"dist":-450,"bCoef":0.1},{"bCoef":0.1,"dist":-200,"normal":[0,-1]},{"bCoef":0.1,"dist":-200,"normal":[0,1]}],"traits":{"ballArea":{"vis":false,"bCoef":1,"cMask":["ball"]},"goalPost":{"radius":8,"invMass":0,"bCoef":0.5},"goalNet":{"vis":true,"bCoef":0.1,"cMask":["ball"]},"kickOffBarrier":{"vis":false,"bCoef":0.1,"cGroup":["redKO","blueKO"],"cMask":["red","blue"]}},"playerPhysics":{"bCoef":0.5,"invMass":0.5,"damping":0.96,"acceleration":0.12,"kickingAcceleration":0.12,"kickingDamping":0.96,"kickStrength":11},"ballPhysics":{"color":"FF99FF","radius":10}
}`
var room = HBInit({
roomName: "🥇🥇 💎 V1 SNİPER 💎 🥇🥇",
maxPlayers: 8,
noPlayer: true, // Remove host player (recommended!)
public: false,
geo : {code: "tr", lat: 41.015137, lon: 28.979530},
});
room.setCustomStadium(stadiımFileText);
room.setScoreLimit(3);
room.setTimeLimit(1);
room.setTeamsLock(true)
var playerData = [];
const getPlayerList = () =>{
playerData = room.getPlayerList();
}
function updateTeamPlayerData(){
getPlayerList()
}
function AdminUpdateTeamPlayer(changedPlayer){
playerData.findIndex((element)=>{
if(element.id == changedPlayer.id){
element.team = changedPlayer.team;
}
})
}
// If there are no admins left in the room give admin to one of the remaining players.
function updateAdmins() {
// Get all players
var players = room.getPlayerList();
if ( players.length == 0 ) return; // No players left, do nothing.
if ( players.find((player) => player.admin) != null ) return; // There's an admin left so do nothing.
room.setPlayerAdmin(players[0].id, true); // Give admin to the first non admin player in the list
}
var isGame = false;
var firstMatch = true;
room.onPlayerTeamChange = (changedPlayer) => {
getPlayerList()
}
room.onGameStop = function(player){
isGame = false;
}
room.onTeamVictory = function(scores){
room.stopGame();
gameStartWin(scores);
}
const gameStartWin = (scores) =>{
if (scores.blue > scores.red){
if(playerData.findIndex((element)=> element.team == 0) != -1){
// yenilen(redin) indexinin döndürür.
const indexRed = playerData.findIndex((element)=>element.team == 1);
// yenen(bluenin) indexinini dönüdürü
const indexBlue = playerData.findIndex((element)=>element.team == 2);
const indexSpec = playerData.findIndex((element)=>element.team == 0);
room.setPlayerTeam(playerData[indexRed].id, 0)
updateTeamPlayerData()
room.setPlayerTeam(playerData[indexSpec].id, 2)
updateTeamPlayerData()
room.setPlayerTeam(playerData[indexBlue].id, 1)
updateTeamPlayerData()
room.startGame()
firstMatch = false;
}
else{
const indexRed = playerData.findIndex((element)=>element.team == 1);
const indexBlue = playerData.findIndex((element)=>element.team == 2);
room.setPlayerTeam(playerData[indexRed].id, 2)
updateTeamPlayerData()
room.setPlayerTeam(playerData[indexBlue].id, 1)
updateTeamPlayerData()
room.startGame()
firstMatch = false;
}
} else if (scores.blue < scores.red){
if(playerData.findIndex((element)=>element.team == 0) != -1){
// yenilen(bluenin) indexinin döndürür.
const indexBlue = playerData.findIndex((element)=>element.team == 2);
// yenen(redin) indexini döndürür.
const indexSpec = playerData.findIndex((element)=>element.team == 0);
room.setPlayerTeam(playerData[indexBlue].id, 0)
room.setPlayerTeam(playerData[indexSpec].id, 2)
updateTeamPlayerData()
room.startGame()
firstMatch = false;
}
else{
room.startGame()
firstMatch = false;
}
}
}
function GameStartFirst(){
var indexArr = [];
playerData.forEach((element,index) =>{
if(element.team == 0){
indexArr.push(index)
}
});
room.setPlayerTeam(playerData[indexArr[0]].id, 1)
updateTeamPlayerData()
room.setPlayerTeam(playerData[indexArr[1]].id, 2)
updateTeamPlayerData()
room.startGame()
firstMatch = false
room.sendAnnouncement("Oda 2 kişiye büyük eşit oldu. Selametle. ", null,0xFF0000, "italic", 2);
}
room.onPlayerJoin = function(player) {
getPlayerList();
room.sendAnnouncement("🔵 Hoşgeldin " + player.name, null, 0xFF0000, "bold", 1)
updateAdmins();
if (room.getPlayerList().length >= 2 && firstMatch == true){
GameStartFirst()
}
}
room.onPlayerLeave = function(player) {
updateAdmins();
// çıkan oyuncunun playerData arrayinden siler.
getPlayerList();
if(player.team == 1){
// çıkan oyuncu red'den çıktıysa
if(playerData.findIndex(element => element.team == 0) != -1){
room.stopGame();
const blueIndex = playerData.findIndex((element)=> element.team == 2);
const specIndex = playerData.findIndex((element)=>element.team == 0);
room.setPlayerTeam(playerData[specIndex].id, 2);
getPlayerList();
room.setPlayerTeam(playerData[blueIndex].id, 1)
room.startGame();
}
}else if(player.team == 2){
// çıkan oyuncu blue'dan çıktıysa
if(playerData.findIndex(element => element.team == 0) != -1){
room.stopGame();
const specIndex = playerData.findIndex((element)=>element.team == 0);
room.setPlayerTeam(playerData[specIndex].id, 2);
getPlayerList();
room.startGame();
}
}
if(playerData.length == 1){
room.stopGame();
room.setPlayerTeam(playerData[0].id, 0)
firstMatch = true;
}else if (playerData.length == 0){
room.stopGame();
firstMatch = true;
}
}