diff --git a/client/html/Pricedown.ttf b/client/html/Pricedown.ttf new file mode 100644 index 0000000..b410cba Binary files /dev/null and b/client/html/Pricedown.ttf differ diff --git a/client/html/app.js b/client/html/app.js new file mode 100644 index 0000000..159f9ee --- /dev/null +++ b/client/html/app.js @@ -0,0 +1,45 @@ +class Component { + constructor({ id }) { + this.$el = document.getElementById(id) + } +} + +class DateComponent extends Component { + constructor(id) { + super(id) + this.renderDate() + } + + renderDate() { + setInterval(() => { + const date = new Date() + this.$el.textContent = `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}` + }) + } +} + +class EngineHealthComponent extends Component { + constructor(id) { + super(id) + } + + renderEngineHealth(engineHealth) { + this.$el.textContent = `engine health: ${engineHealth}` + } + + clearDisplay() { + this.$el.textContent = `` + } +} + + +const dateComponent = new DateComponent({ id: 'date' }) +const engineHealthComponent = new EngineHealthComponent({ id: 'engineHealth' }) + +if ('alt' in window) { + alt.on('display:engineHealth', engineHealth => engineHealthComponent.renderEngineHealth(engineHealth)) + alt.on('displayClear:engineHealth', () => engineHealthComponent.clearDisplay()) + alt.emit('ready') +} else { + engineHealthComponent.$el.textContent = `engine health: 0` +} \ No newline at end of file diff --git a/client/html/index.html b/client/html/index.html new file mode 100644 index 0000000..e5c6e61 --- /dev/null +++ b/client/html/index.html @@ -0,0 +1,30 @@ + + + + + + + Document + + +
+
+
+

+ Copchase server

+
+
+
+ +
+
+
+ +
+ + + \ No newline at end of file diff --git a/client/html/style.css b/client/html/style.css new file mode 100644 index 0000000..1da8e8c --- /dev/null +++ b/client/html/style.css @@ -0,0 +1,54 @@ +@font-face { + font-family: "Pricedown"; + src: url("./Pricedown.ttf") format("truetype"); +} + +* { + box-sizing: border-box; + -moz-user-select: none; + -khtml-user-select: none; + user-select: none; +} + + h1, h2, h3, h4, h5, h6, p { + padding: 0; + margin: 0; + } + +.container { + padding: 25px; + color: #fff; + font-family: 'Pricedown'; +} +.container .container-header { + display: flex; + flex-direction: column; + align-items: flex-end; +} +.container .container-header .container-header__title { + font-size: 38px; +} + +.container .container-header .container-header__title p { + display: flex; + -webkit-text-stroke-width: 1.6px; + -webkit-text-stroke-color: black; +} + +.container .container-header .container-header__title svg { + align-items: center; + margin-right: 15px; + width: 32px; +} + +.container .container-header .container-header__date { + font-size: 18px; + font-family: 'Open Sans'; + margin-top: 5px; + color: #fff; +} + +.container-footer #engineHealth { + color: #fff; + font-size: 28px; +} \ No newline at end of file diff --git a/client/index.mjs b/client/index.mjs index cd4ca55..335aac0 100644 --- a/client/index.mjs +++ b/client/index.mjs @@ -6,6 +6,8 @@ import './ui.mjs' import './modules/blips.mjs' +const webview = new alt.WebView('http://resource/client/html/index.html') + alt.setMsPerGameMinute(30000) alt.onServer('player:death', () => { @@ -32,11 +34,20 @@ alt.onServer('player:delInvincible', () => { }) alt.onServer('vehicle:setInto', (newVehicle) => { - const localPlayer = alt.Player.local.scriptID - - alt.setTimeout(() => { - native.setPedIntoVehicle(localPlayer, newVehicle.scriptID, -1) - }, 400) + let cleared = false; + const interval = alt.setInterval(() => { + const vehicleScriptId = newVehicle.scriptID; + if (vehicleScriptId) { + native.setPedIntoVehicle(alt.Player.local.scriptID, vehicleScriptId, -1); + alt.clearInterval(interval); + cleared = true; + } + }, 10); + alt.setTimeout(() => { + if (!cleared) { + alt.clearInterval(interval); + } + }, 500); }) alt.onServer('admin:setStat', () => { @@ -45,4 +56,11 @@ alt.onServer('admin:setStat', () => { alt.onServer('admin:setInvincible', toggle => { native.setEntityInvincible(alt.Player.local.scriptID, toggle) +}) + + +alt.onServer('webview:load', () => { + webview.on('ready', () => { + + }) }) \ No newline at end of file diff --git a/client/modules/blips.mjs b/client/modules/blips.mjs index 0788f9a..975e67e 100644 --- a/client/modules/blips.mjs +++ b/client/modules/blips.mjs @@ -1,37 +1,43 @@ import * as alt from 'alt' -const blips = {} - alt.everyTick(() => { alt.Player.all.forEach(_player => { - if (blips[_player.id]) { - blips[_player.id].pos = _player.pos + if (!_player.valid) { + return + } + + if (_player.blip && _player.blip !== null) { + _player.blip.pos = _player.getSyncedMeta('pos') } }) }) alt.onServer('player:createBlipPlayers', ({ players, color }) => { players.forEach(_player => { - if (_player.name !== alt.Player.local.name) { - blips[_player.id] = new alt.PointBlip(_player.pos.x, _player.pos.y, _player.pos.z) - blips[_player.id].name = _player.name - blips[_player.id].color = color + if (_player.id === alt.Player.local.id) { + return } + + _player.blip = new alt.PointBlip(_player.pos.x, _player.pos.y, _player.pos.z) + _player.blip.name = _player.name + _player.blip.color = color + _player.blip.shortRange = false; + _player.blip.owner = _player; }) }) alt.onServer('player:deleteBlipPlayers', () => { alt.Player.all.forEach(_player => { - if (blips[_player.id]) { - blips[_player.id].destroy() - blips[_player.id] = null + if (_player.blip) { + _player.blip.destroy() + _player.blip = null } }) }) alt.onServer('player:deleteBlipPlayer', player => { - if (blips[player.id]) { - blips[player.id].destroy() - blips[player.id] = null + if (player.blip) { + player.blip.destroy() + player.blip = null } }) \ No newline at end of file diff --git a/server/modules/copchase.mjs b/server/modules/copchase.mjs index 8329d76..6c69b01 100644 --- a/server/modules/copchase.mjs +++ b/server/modules/copchase.mjs @@ -34,7 +34,6 @@ class Copchase { 'vamos', 'chino', 'moonbeam', - 'elegy2', 'dubsta', 'dominator', 'rebla', @@ -74,14 +73,14 @@ class Copchase { this.suspect = null this.positions = { suspect: [ - { x: 395.185, y: -999.645, z: 28.755 }, - { x: 404.691, y: -1907.0604, z: 24.723 }, - { x: 2619.436, y: 3374.145, z: 55.619 } + { x: 387.006, y: -766.760, z: 28.723 }, + { x: 442.483, y: -1507.068, z: 28.605 }, + { x: 1924.773, y: 3819.125, z: 31.588 } ], police: [ { x: 442.308, y: -1025.066, z: 28.231 }, - { x: 348.865, y: -1966.507, z: 24.133 }, - { x: 2681.454, y: 3457.637, z: 55.228 } + { x: 396.105, y: -1643.973, z: 28.757 }, + { x: 1847.670, y: 3671.854, z: 33.172 } ] } } @@ -99,7 +98,7 @@ class Copchase { } isPlayerInGame(player) { - if(this.players.find(_player => _player.name === player.name) !== undefined) { + if(this.players.find(_player => _player.id === player.id) !== undefined) { send(player, '{EE9A00}[COPCHASE]: {FF0000}Дождитесь окончания игры!') return true } else { @@ -108,7 +107,7 @@ class Copchase { } isPlayerInWaitingRoom(player) { - if(this.waitingPlayers.find(_player => _player.name === player.name) !== undefined) { + if(this.waitingPlayers.find(_player => _player.id === player.id) !== undefined) { return true } else { return false @@ -125,7 +124,7 @@ class Copchase { } selectSuspect() { - this.suspect = this.players[Math.floor(Math.random() * (this.players.length - 1 - 0 + 1) + 0)] + this.suspect = this.players[Math.floor(Math.random() * this.players.length)] } messageToPlayersInGame(message) { @@ -143,7 +142,7 @@ class Copchase { } notifyPolicePlayers(message) { - this.players.forEach(_player => _player.name !== this.suspect.name ? alt.emitClient(_player, 'player:notify', message) : false) + this.players.forEach(_player => _player.id !== this.suspect.id ? alt.emitClient(_player, 'player:notify', message) : false) } notifySuspectPlayer(message) { @@ -157,17 +156,13 @@ class Copchase { return new Promise((resolve, reject) => { this.players.forEach(_player => { - if (_player.name === this.suspect.name) { + if (_player.id === this.suspect.id) { _player.pos = suspectPosition setTimeout(() => _player.health = 200, 300) _player.dimension = this.dimension _player.model = skins[Math.floor(Math.random() * (430 - 1 - 422) + 422)] alt.emitClient(_player, 'player:delInvincible') alt.emitClient(_player, 'player:showMidsizedMessage', '~r~Вы саспект!', 'Уйдите от полицейских.', 5000) - this.players.forEach(_player => _player.name === this.suspect.name - ? alt.emitClient(_player, 'player:createBlipPlayers', { players: this.players, color: 38 }) - : alt.emitClient(_player, 'player:createBlipPlayers', { players: this.players, color: 1 }) - ) } else { posX = posX + 3 _player.pos = { @@ -182,6 +177,14 @@ class Copchase { _player.giveWeapon('0x3656C8C1', 100, true) alt.emitClient(_player, 'player:delInvincible') alt.emitClient(_player, 'player:showMidsizedMessage', `~w~Саспект: ~r~${this.suspect.name}`, 'Нейтрализуйте саспекта.', 5000) + alt.emitClient(_player, 'player:createBlipPlayers', { + players: this.players.filter(player => player.id !== this.suspect.id), + color: 38 + }) // create friendly blips + alt.emitClient(_player, 'player:createBlipPlayers', { + players: this.players.filter(player => player.id === this.suspect.id), + color: 1 + }) // create suspec blip } }) @@ -191,7 +194,7 @@ class Copchase { spawnCars() { this.players.forEach(_player => { - if (_player.name === this.suspect.name) { + if (_player.id === this.suspect.id) { const carSuspect = new alt.Vehicle( this.suspectCars[Math.floor(Math.random() * (this.suspectCars.length - 1 - 0) + 0)], _player.pos.x, _player.pos.y, _player.pos.z, @@ -288,7 +291,7 @@ class Copchase { if (winner === 'police') { this.players.forEach(_player => { - if (_player.name !== this.suspect.name) { + if (_player.id !== this.suspect.id) { alt.emitClient(_player, 'player:showMidsizedMessage', '~g~Вы выиграли', 'Саспект был нейтрализован.') } }) @@ -297,7 +300,7 @@ class Copchase { if (winner === 'suspect') { this.players.forEach(_player => { - if (_player.name === this.suspect.name) { + if (_player.id === this.suspect.id) { alt.emitClient(_player, 'player:showMidsizedMessage', '~g~Вы выиграли', 'Вы успешно ушли от полиции.') } else { alt.emitClient(_player, 'player:showMidsizedMessage', '~r~Вы проиграли', 'Саспект скрылся.') @@ -317,7 +320,7 @@ const copchase = new Copchase({ maxPlayers: 11, minPlayers: 2, timeRemaining: 10, - timeToStart: 4 + timeToStart: 5 }) export { diff --git a/server/modules/events/playerConnect.mjs b/server/modules/events/playerConnect.mjs index 3983f1f..8976a54 100644 --- a/server/modules/events/playerConnect.mjs +++ b/server/modules/events/playerConnect.mjs @@ -14,6 +14,18 @@ alt.on('playerConnect', (player) => { player.spawn(config.spawn.x, config.spawn.y,config.spawn.z) player.dimension = 0 + alt.emitClient(player, 'webview:load') alt.emitClient(player, 'player:setInvincible') alt.emitClient(player, 'player:notify', '~g~Добро пожаловать на сервер!') }) + +// sync +alt.setInterval(() => { + alt.Player.all.forEach(_player => { + if (!_player.valid) { + return + } + + _player.setSyncedMeta('pos', _player.pos) + }) +}, 100) \ No newline at end of file diff --git a/server/modules/events/playerDeath.mjs b/server/modules/events/playerDeath.mjs index cab8711..3a9b45f 100644 --- a/server/modules/events/playerDeath.mjs +++ b/server/modules/events/playerDeath.mjs @@ -11,9 +11,9 @@ alt.on('playerDeath', (player) => { }) if (copchase.isStarted) { - if (player.name === copchase.suspect.name) copchase.stopGame({ winner: 'police' }) + if (player.id === copchase.suspect.id) copchase.stopGame({ winner: 'police' }) - const policemanIndex = copchase.players.findIndex(_player => _player.name === player.name && _player.name !== copchase.suspect.name) + const policemanIndex = copchase.players.findIndex(_player => _player.id === player.id && _player.id !== copchase.suspect.id) if (policemanIndex !== -1) copchase.players.splice(policemanIndex, 1) if (copchase.players.length <= 1 && copchase.suspect !== null) copchase.stopGame({ winner: 'suspect' }) } @@ -23,5 +23,6 @@ alt.on('playerDeath', (player) => { player.dimension = 0 player.removeAllWeapons() alt.emitClient(player, 'player:setInvincible') + alt.emitClient(player, 'player:deleteBlipPlayers') }, 5000) }) \ No newline at end of file diff --git a/server/modules/events/playerDisconnect.mjs b/server/modules/events/playerDisconnect.mjs index edbfcf9..710715a 100644 --- a/server/modules/events/playerDisconnect.mjs +++ b/server/modules/events/playerDisconnect.mjs @@ -6,18 +6,18 @@ alt.on('playerDisconnect', (player) => { broadcast(`{EE9A00}[SERVER]: {1CD8FD}😭 ${player.name} {FFF}покинул нас`) if (copchase.isPlayerInWaitingRoom(player)) { - const disconnectedPlayerIndex = copchase.waitingPlayers.findIndex(_player => _player.name === player.name) + const disconnectedPlayerIndex = copchase.waitingPlayers.findIndex(_player => _player.id === player.id) copchase.waitingPlayers.splice(disconnectedPlayerIndex, 1) } if (copchase.isStarted) { - if (player.name === copchase.suspect.name) { - const suspectIndex = copchase.players.findIndex(_player => _player.name === copchase.suspect.name) + if (player.id === copchase.suspect.id) { + const suspectIndex = copchase.players.findIndex(_player => _player.id === copchase.suspect.id) copchase.players.splice(suspectIndex, 1) copchase.stopGame({ winner: 'police' }) } - const policemanIndex = copchase.players.findIndex(_player => _player.name === player.name && _player.name !== copchase.suspect.name) + const policemanIndex = copchase.players.findIndex(_player => _player.id === player.id && _player.id !== copchase.suspect.id) if (policemanIndex !== -1) copchase.players.splice(policemanIndex, 1) if (copchase.players.length <= 1 && copchase.suspect !== null) copchase.stopGame({ winner: 'suspect' }) diff --git a/server/modules/events/playerLeftVehicle.mjs b/server/modules/events/playerLeftVehicle.mjs index ab47dc8..2b4da4a 100644 --- a/server/modules/events/playerLeftVehicle.mjs +++ b/server/modules/events/playerLeftVehicle.mjs @@ -2,11 +2,11 @@ import alt from 'alt-server' import { copchase } from '../copchase.mjs' alt.on('playerLeftVehicle', player => { - if (copchase.isStarted && player.name === copchase.suspect.name) { + if (copchase.isStarted && player.id === copchase.suspect.id) { player.giveWeapon('0x1B06D571', 25, true); copchase.players.forEach(_player => { - if (_player.name !== copchase.suspect.name) { + if (_player.id !== copchase.suspect.id) { _player.giveWeapon('0x1B06D571', 50, true); } })