From 17c2392a6422eab93139701ffe75f2c7e43b08be Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 22 Apr 2021 17:24:22 +0200 Subject: [PATCH] =?UTF-8?q?index.js=20vom=20polygon=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Player/{position.ts => nodm.ts} | 4 +- ReallifeGamemode.Client/index.ts | 4 +- ReallifeGamemode.Client/polygons/index.js | 48 +++++++++++++++++++ ReallifeGamemode.Client/util/weapondamage.ts | 3 +- 4 files changed, 53 insertions(+), 6 deletions(-) rename ReallifeGamemode.Client/Player/{position.ts => nodm.ts} (85%) create mode 100644 ReallifeGamemode.Client/polygons/index.js diff --git a/ReallifeGamemode.Client/Player/position.ts b/ReallifeGamemode.Client/Player/nodm.ts similarity index 85% rename from ReallifeGamemode.Client/Player/position.ts rename to ReallifeGamemode.Client/Player/nodm.ts index 3e2d802d..89946fac 100644 --- a/ReallifeGamemode.Client/Player/position.ts +++ b/ReallifeGamemode.Client/Player/nodm.ts @@ -7,14 +7,14 @@ export function isPlayerInNoDMZone(pos) { return false; } -export default function positionHandler() { +export default function nodmHandler() { mp.events.add('playerEnterPolygon', (polygon) => { mp.gui.chat.push("entered"); }); mp.events.add('playerLeavePolygon', (polygon) => { - mp.gui.chat.push("entered"); + mp.gui.chat.push("leaved"); }); setInterval(() => { diff --git a/ReallifeGamemode.Client/index.ts b/ReallifeGamemode.Client/index.ts index d8e3350f..598922bf 100644 --- a/ReallifeGamemode.Client/index.ts +++ b/ReallifeGamemode.Client/index.ts @@ -186,8 +186,8 @@ ped(); import reportList from './Player/reportmenu'; reportList(globalData); -import positionHandler from './Player/position'; -positionHandler(); +import nodmHandler from './Player/nodm'; +nodmHandler(); import checkpointHandle from './util/checkpoint'; checkpointHandle(globalData); diff --git a/ReallifeGamemode.Client/polygons/index.js b/ReallifeGamemode.Client/polygons/index.js new file mode 100644 index 00000000..5393a075 --- /dev/null +++ b/ReallifeGamemode.Client/polygons/index.js @@ -0,0 +1,48 @@ +const { generateUniquePolygonId, getAngleSumBetweenPositionAndVertices, isPointInArea2D } = require('polygons/helpers'); +require('polygons/render'); +require('polygons/events'); + +mp.polygons = { + pool: [], + add: (vertices, height, options = { visible: false, lineColorRGBA: [255,255,255,255], dimension: 0 }) => { + + const polygon = { + id: generateUniquePolygonId(), + vertices, + height, + ...options, + colliding: false + } + + mp.polygons.pool.push(polygon); + + return polygon; + }, + remove: (polygon) => { + const index = mp.polygons.pool.findIndex(p => p.id === polygon.id); + + if (index !== -1) + mp.polygons.pool.splice(index, 1); + }, + exists: (polygon) => { + return mp.polygons.pool.some(p => p.id === polygon.id) + }, + isPositionWithinPolygon: (position, polygon, dimension) => { + if (dimension && polygon.dimension !== dimension && polygon.dimension !== -1) + return false; + + const { vertices } = polygon; + + const polygonPoints2D = []; + + for (let i in vertices) { + if (position.z >= vertices[i].z && position.z <= (vertices[i].z + polygon.height) || getAngleSumBetweenPositionAndVertices(position, vertices) >= 5.8) + polygonPoints2D.push([vertices[i].x, vertices[i].y]); + else + return false; + } + + return isPointInArea2D([position.x, position.y], polygonPoints2D); + } +} + diff --git a/ReallifeGamemode.Client/util/weapondamage.ts b/ReallifeGamemode.Client/util/weapondamage.ts index f1704e9a..4c16d9f8 100644 --- a/ReallifeGamemode.Client/util/weapondamage.ts +++ b/ReallifeGamemode.Client/util/weapondamage.ts @@ -1,4 +1,4 @@ -import { isPlayerInNoDMZone } from "../Player/position"; +import { isPlayerInNoDMZone } from "../Player/nodm"; export default function weapondamageUtil() { let blockInput = false; @@ -11,7 +11,6 @@ export default function weapondamageUtil() { mp.events.add('outgoingDamage', (sourceEntity, targetEntity, sourcePlayer, weapon, boneIndex, damage) => { if (isPlayerInNoDMZone(targetEntity.position) || isPlayerInNoDMZone(sourceEntity.position)) { - mp.gui.chat.push("Kein DM in NODM!"); return true; } });