From a979c36c3875c61a579a2a62865e579ffd6dc7f0 Mon Sep 17 00:00:00 2001 From: suryabhaiin <54040750+suryabhaiin@users.noreply.github.com> Date: Sun, 17 Mar 2024 07:27:05 +0530 Subject: [PATCH 01/10] Any Vector copy Any Vector copy like vector3, vector3, heading and cords in json format --- client/laser.lua | 137 +++++++++++++++++++++++++++++++++++++++++++++++ fxmanifest.lua | 2 +- 2 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 client/laser.lua diff --git a/client/laser.lua b/client/laser.lua new file mode 100644 index 0000000..82a5f47 --- /dev/null +++ b/client/laser.lua @@ -0,0 +1,137 @@ +local laserEnabled = false +local laserEndPoint = nil +lib.hideTextUI() +local function roundcord(value, numDecimalPlaces) + if not numDecimalPlaces then return math.floor(value + 0.5) end + local power = 10 ^ numDecimalPlaces + return math.floor((value * power) + 0.5) / (power) +end + +local RotationToDirection = function(rotation) + local adjustedRotation = { + x = (math.pi / 180) * rotation.x, + y = (math.pi / 180) * rotation.y, + z = (math.pi / 180) * rotation.z + } + local direction = { + x = -math.sin(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)), + y = math.cos(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)), + z = math.sin(adjustedRotation.x) + } + return direction +end +local RayCastGamePlayCamera = function(distance) + -- Checks to see if the Gameplay Cam is Rendering or another is rendering (no clip functionality) + local currentRenderingCam = false + if not IsGameplayCamRendering() then + currentRenderingCam = GetRenderingCam() + end + + local cameraRotation = not currentRenderingCam and GetGameplayCamRot() or GetCamRot(currentRenderingCam, 2) + local cameraCoord = not currentRenderingCam and GetGameplayCamCoord() or GetCamCoord(currentRenderingCam) + local direction = RotationToDirection(cameraRotation) + local destination = { + x = cameraCoord.x + direction.x * distance, + y = cameraCoord.y + direction.y * distance, + z = cameraCoord.z + direction.z * distance + } + local _, b, c, _, e = GetShapeTestResult(StartShapeTestRay(cameraCoord.x, cameraCoord.y, cameraCoord.z, destination.x, destination.y, destination.z, -1, PlayerPedId(), 0)) + return b, c, e +end +-- Function to draw the laser effect +function drawLaser() + local playerPed = PlayerPedId() + lib.showTextUI("COPY : [E] vector3 | [Q] vector4 | [F] coords | [R] Json | [H] Heading", {position = 'top-center'}) + while laserEnabled do + local color = { r = 106, g = 255, b = 54, a = 200 } + local position = GetEntityCoords(playerPed) + local hit, coords, entity = RayCastGamePlayCamera(1000.0) + -- If entity is found then verify entity + if IsControlJustReleased(0, 51) then -- Copy Vector3 Coords + local x = roundcord(coords.x, 2) + local y = roundcord(coords.y, 2) + local z = roundcord(coords.z, 2) + laserEndPoint = string.format('vector3(%s, %s, %s)', x, y, z) + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Vector3 Copied', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + end + if IsControlJustReleased(0, 52) then -- Copy Vector4 Coords + local x = roundcord(coords.x, 2) + local y = roundcord(coords.y, 2) + local z = roundcord(coords.z, 2) + local w = roundcord(GetEntityHeading(GetPlayerPed(-1)), 2) + laserEndPoint = string.format('vector4(%s, %s, %s, %s)', x, y, z, w) + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Vector3 Copied', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + end + if IsControlJustReleased(0, 45) then -- Copy Coords In json + local x = roundcord(coords.x, 2) + local y = roundcord(coords.y, 2) + local z = roundcord(coords.z, 2) + local w = roundcord(GetEntityHeading(GetPlayerPed(-1)), 2) + laserEndPoint = string.format('{x = %s, y = %s, z = %s, w = %s)', x, y, z, w) + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Vector3 Copied', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + end + if IsControlJustReleased(0, 74) then -- Copy Heading + laserEndPoint = string.format('%s', roundcord(GetEntityHeading(GetPlayerPed(-1)), 2)) + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Heading Copied', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + end + if IsControlJustReleased(0, 75) then -- Copy Coords without vetor + local x = roundcord(coords.x, 2) + local y = roundcord(coords.y, 2) + local z = roundcord(coords.z, 2) + laserEndPoint = string.format('%s, %s, %s', x, y, z) + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Cord Copied', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + end + DrawLine(position.x, position.y, position.z, coords.x, coords.y, coords.z, color.r, color.g, color.b, color.a) + DrawMarker(28, coords.x, coords.y, coords.z, 0.0, 0.0, 0.0, 0.0, 180.0, 0.0, 0.1, 0.1, 0.1, color.r, color.g, color.b, color.a, false, true, 2, nil, nil, false, false) + Wait(10) + end + lib.hideTextUI() +end + + +-- Command handler +RegisterCommand("plaser", function() + laserEnabled = not laserEnabled + if not laserEnabled then + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Vector3 Copied', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + laserEndPoint = nil + else + drawLaser() + end +end) diff --git a/fxmanifest.lua b/fxmanifest.lua index 1cc85b6..1bebc54 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -20,7 +20,7 @@ client_scripts { '@PolyZone/client.lua', '@PolyZone/BoxZone.lua', '@PolyZone/EntityZone.lua', - 'client/client.lua' + 'client/*.lua' } server_scripts { From ee717a9eac35a75efbd310d0d2d42f80f6cb3bec Mon Sep 17 00:00:00 2001 From: suryabhaiin <54040750+suryabhaiin@users.noreply.github.com> Date: Sun, 17 Mar 2024 08:46:00 +0530 Subject: [PATCH 02/10] Coordinate copy Any Coordinate copy like vector3, vector3, heading and only coordinate and coordinate in json format Commands restricted for admin --- README.md | 8 +++++--- client/client.lua | 15 +++++++++++---- client/laser.lua | 40 +++++++++++++--------------------------- server/server.lua | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 32b9c4d..d8a32ba 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # `polygun` -Easily create polyzones around objects and save for configuring +Easily create polyzones around objects and save for configuring ![image](https://github.com/BryceRussell/polygun/assets/19967622/26c96993-aba7-4089-8cde-1d1956919651) @@ -19,9 +19,11 @@ Easily create polyzones around objects and save for configuring 2) Equip a gun and aim it at an object to select it 3) (**Optional**) Tweak size - - **Scroll**: Scale XYZ + - **Scroll**: Scale XYZ - **Up/Down Arrows**: Scale X - **Right/Left Arrows**: Scale Y - **Page Up/Down**: Scale Z -4) Press `E` (or use `/polygunsave`) to save it to the `zones.txt` file inside the resource +4) Press `E` (or use `/polygunsave`) to save it to the `zones.txt` file inside the resource + +5) Enable only coordinate copy from laser point `/plaser` diff --git a/client/client.lua b/client/client.lua index 8a277c1..c0d7500 100644 --- a/client/client.lua +++ b/client/client.lua @@ -163,8 +163,15 @@ ToggleInfos = function() -- "ToggleInfos" is a function Config.loopOn = not Config.loopOn -- Switch them around end -- Ending the function here. --- Creating the command. -RegisterCommand("polygun", function() -- Listen for this command. +RegisterNetEvent('polygun:runpolygun', function() destoryZone() - ToggleInfos() -- Heard it! Let's toggle the function above. -end) -- Ending the function here. + ToggleInfos() + if Config.loopOn then + lib.notify({ + title = 'Info', + duration = 7500, + description = 'Get Gun In hand and aim to entity', + type = 'success' + }) + end +end) \ No newline at end of file diff --git a/client/laser.lua b/client/laser.lua index 82a5f47..fec7a3d 100644 --- a/client/laser.lua +++ b/client/laser.lua @@ -41,16 +41,18 @@ end -- Function to draw the laser effect function drawLaser() local playerPed = PlayerPedId() + local player = PlayerId() lib.showTextUI("COPY : [E] vector3 | [Q] vector4 | [F] coords | [R] Json | [H] Heading", {position = 'top-center'}) while laserEnabled do - local color = { r = 106, g = 255, b = 54, a = 200 } + local color = { r = 255, g = 255, b = 255, a = 200 } local position = GetEntityCoords(playerPed) local hit, coords, entity = RayCastGamePlayCamera(1000.0) - -- If entity is found then verify entity + local heading = GetEntityHeading(GetPlayerPed(-1)) + local x = roundcord(coords.x, 2) + local y = roundcord(coords.y, 2) + local z = roundcord(coords.z, 2) + local w = roundcord(heading, 2) if IsControlJustReleased(0, 51) then -- Copy Vector3 Coords - local x = roundcord(coords.x, 2) - local y = roundcord(coords.y, 2) - local z = roundcord(coords.z, 2) laserEndPoint = string.format('vector3(%s, %s, %s)', x, y, z) lib.setClipboard(laserEndPoint) lib.notify({ @@ -61,10 +63,6 @@ function drawLaser() }) end if IsControlJustReleased(0, 52) then -- Copy Vector4 Coords - local x = roundcord(coords.x, 2) - local y = roundcord(coords.y, 2) - local z = roundcord(coords.z, 2) - local w = roundcord(GetEntityHeading(GetPlayerPed(-1)), 2) laserEndPoint = string.format('vector4(%s, %s, %s, %s)', x, y, z, w) lib.setClipboard(laserEndPoint) lib.notify({ @@ -75,10 +73,7 @@ function drawLaser() }) end if IsControlJustReleased(0, 45) then -- Copy Coords In json - local x = roundcord(coords.x, 2) - local y = roundcord(coords.y, 2) - local z = roundcord(coords.z, 2) - local w = roundcord(GetEntityHeading(GetPlayerPed(-1)), 2) + laserEndPoint = string.format('{x = %s, y = %s, z = %s, w = %s)', x, y, z, w) lib.setClipboard(laserEndPoint) lib.notify({ @@ -89,7 +84,7 @@ function drawLaser() }) end if IsControlJustReleased(0, 74) then -- Copy Heading - laserEndPoint = string.format('%s', roundcord(GetEntityHeading(GetPlayerPed(-1)), 2)) + laserEndPoint = string.format('%s', w) lib.setClipboard(laserEndPoint) lib.notify({ title = 'Heading Copied', @@ -105,7 +100,7 @@ function drawLaser() laserEndPoint = string.format('%s, %s, %s', x, y, z) lib.setClipboard(laserEndPoint) lib.notify({ - title = 'Cord Copied', + title = 'Coordinate Copied', duration = 7500, description = laserEndPoint, type = 'success' @@ -118,20 +113,11 @@ function drawLaser() lib.hideTextUI() end - --- Command handler -RegisterCommand("plaser", function() - laserEnabled = not laserEnabled +RegisterNetEvent('polygun:runlaser', function() + laserEnabled = not laserEnabled if not laserEnabled then - lib.setClipboard(laserEndPoint) - lib.notify({ - title = 'Vector3 Copied', - duration = 7500, - description = laserEndPoint, - type = 'success' - }) laserEndPoint = nil else drawLaser() end -end) +end) \ No newline at end of file diff --git a/server/server.lua b/server/server.lua index 1f4353f..c26bdea 100644 --- a/server/server.lua +++ b/server/server.lua @@ -5,3 +5,17 @@ AddEventHandler("polygun:save", function(zone, text) io.write("--Name: " .. zone.name .. " | " .. os.date("!%Y-%m-%dT%H:%M:%SZ\n") .. text) io.close(file) end) + +lib.addCommand('polygun', { + help = 'Create Polyzon at entity', + restricted = 'group.admin' +}, function(source, args, raw) + TriggerClientEvent("polygun:runpolygun", source) +end) + +lib.addCommand('plaser', { + help = 'Copy coordinates at laser point', + restricted = 'group.admin' +}, function(source, args, raw) + TriggerClientEvent("polygun:runlaser", source) +end) From 6d41828db11fc897e4a726f232e2680daf13c84f Mon Sep 17 00:00:00 2001 From: suryabhaiin <54040750+suryabhaiin@users.noreply.github.com> Date: Sun, 17 Mar 2024 10:02:16 +0530 Subject: [PATCH 03/10] Create Zone At pointed cooardinate Create Zone At pointed cooardinate --- client/laser.lua | 138 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 2 deletions(-) diff --git a/client/laser.lua b/client/laser.lua index fec7a3d..976142e 100644 --- a/client/laser.lua +++ b/client/laser.lua @@ -1,3 +1,4 @@ +local RESULT, HEADING, ENTITY, NAME, COORDS, PREVIOUS, ZONE, PREVIOUSZONE, SCALEX, SCALEY, SCALEZ local laserEnabled = false local laserEndPoint = nil lib.hideTextUI() @@ -38,11 +39,88 @@ local RayCastGamePlayCamera = function(distance) local _, b, c, _, e = GetShapeTestResult(StartShapeTestRay(cameraCoord.x, cameraCoord.y, cameraCoord.z, destination.x, destination.y, destination.z, -1, PlayerPedId(), 0)) return b, c, e end + + +local function parseBox(zone) + return + "{\n" + .. + "\tcoords = " .. + "vector3(" .. + tostring(roundcord(zone.center.x, 2)) .. + ", " .. tostring(roundcord(zone.center.y, 2)) .. ", " .. tostring(roundcord(zone.center.z, 2)) .. "),\n" + .. "\tlength = " .. tostring(SCALEX) .. ",\n" + .. "\twidth = " .. tostring(SCALEY) .. ",\n" + .. "\tname = \"" .. zone.name .. "\",\n" + .. "\theading = " .. tostring(HEADING) .. ",\n" + .. "\tminZ = " .. tostring(roundcord(zone.minZ, 2)) .. ",\n" + .. "\tmaxZ = " .. tostring(roundcord(zone.maxZ, 2)) .. ",\n" + .. "}\n" +end + +local function destoryZone() + if ZONE then ZONE:destroy() end +end + +local function drawEntityZone() + destoryZone() + ZONE = EntityZone:Create(ENTITY, { + name = NAME, + debugPoly = true, + useZ = true, + scale = scale or { SCALEX, SCALEY, SCALEZ } + }) +end + +function createEntity() + local input = lib.inputDialog('Dialog title', { + {type = 'input', label = 'Zone Name', description = 'Enter Zone name', required = true, min = 4, max = 16}, + {type = 'number', label = 'Width X', description = 'Enter width size', required = true, icon = 'hashtag'}, + {type = 'number', label = 'Height Y', description = 'Enter height size', required = true, icon = 'hashtag'}, + {type = 'number', label = 'Height Z', description = 'Enter height for Z', required = true, icon = 'hashtag'}, + }) + if not input then return end + print(json.encode(input), input[1], input[2]) + local modelName = "prop_parking_sign_1" + NAME = input[1] + SCALEX = input[2] + SCALEY = input[3] + SCALEZ = input[4] + if DoesEntityExist(ENTITY) then + DeleteEntity(ENTITY) + end + RequestModel(modelName) + while not HasModelLoaded(modelName) do + Wait(500) + end + ENTITY = CreateObject(modelName, laserEndPoint.x, laserEndPoint.y, laserEndPoint.z, true, true, true) + SetEntityHeading(ENTITY, HEADING) + Wait(100) + drawEntityZone() +end + +function saveZone() + if ZONE then + local text = parseBox(ZONE) + if Config.clipboard then lib.setClipboard(text) end + TriggerServerEvent('polygun:save', ZONE, text) + lib.notify({ + title = 'Box Zone Saved', + duration = 7500, + description = 'Check zones.txt inside the polygun resource', + type = 'success' + }) + if DoesEntityExist(ENTITY) then + DeleteEntity(ENTITY) + end + destoryZone() + end +end + -- Function to draw the laser effect function drawLaser() local playerPed = PlayerPedId() - local player = PlayerId() - lib.showTextUI("COPY : [E] vector3 | [Q] vector4 | [F] coords | [R] Json | [H] Heading", {position = 'top-center'}) + lib.showTextUI("COPY : [E] vector3 | [Q] vector4 | [F] coords | [R] Json | [H] Heading | [G] Add Zone | [X] Save Zone", {position = 'top-center'}) while laserEnabled do local color = { r = 255, g = 255, b = 255, a = 200 } local position = GetEntityCoords(playerPed) @@ -52,6 +130,16 @@ function drawLaser() local y = roundcord(coords.y, 2) local z = roundcord(coords.z, 2) local w = roundcord(heading, 2) + HEADING = w + if IsControlJustReleased(0, 73) then --save zone + saveZone() + Wait(1000) + end + if IsControlJustReleased(0, 58) then -- G add zone + laserEndPoint = coords + createEntity() + Wait(1000) + end if IsControlJustReleased(0, 51) then -- Copy Vector3 Coords laserEndPoint = string.format('vector3(%s, %s, %s)', x, y, z) lib.setClipboard(laserEndPoint) @@ -106,6 +194,45 @@ function drawLaser() type = 'success' }) end + if IsControlJustPressed(0, 241) or IsDisabledControlPressed(1, 241) then -- Scroll Up + SCALEX = SCALEX + Config.addX + SCALEY = SCALEY + Config.addY + SCALEZ = SCALEZ + Config.addZ + drawEntityZone() + end + if IsControlJustPressed(0, 242) or IsDisabledControlPressed(1, 242) then -- Scroll down + SCALEX = SCALEX - Config.subX + SCALEY = SCALEY - Config.subY + SCALEZ = SCALEZ - Config.subZ + drawEntityZone() + end + + if IsControlPressed(1, Config.addXControl) or IsDisabledControlPressed(1, Config.addXControl) then -- Up Arrow + SCALEX = SCALEX + Config.addX + drawEntityZone() + end + if IsControlPressed(1, Config.subXControl) or IsDisabledControlPressed(1, Config.subXControl) then -- Down Arrow + SCALEX = SCALEX - Config.subZ + drawEntityZone() + end + + if IsControlPressed(1, Config.subYControl) or IsDisabledControlPressed(1, Config.subYControl) then -- Left Arrow + SCALEY = SCALEY - Config.subY + drawEntityZone() + end + if IsControlPressed(1, Config.addYControl) or IsDisabledControlPressed(1, Config.addYControl) then -- Right Arrow + SCALEY = SCALEY + Config.addY + drawEntityZone() + end + + if IsControlPressed(1, Config.addZControl) or IsDisabledControlPressed(1, Config.addZControl) then -- Page Up + SCALEZ = SCALEZ + Config.addZ + drawEntityZone() + end + if IsControlPressed(1, Config.subZControl) or IsDisabledControlPressed(1, Config.subZControl) then -- Page Down + SCALEZ = SCALEZ - Config.subZ + drawEntityZone() + end DrawLine(position.x, position.y, position.z, coords.x, coords.y, coords.z, color.r, color.g, color.b, color.a) DrawMarker(28, coords.x, coords.y, coords.z, 0.0, 0.0, 0.0, 0.0, 180.0, 0.0, 0.1, 0.1, 0.1, color.r, color.g, color.b, color.a, false, true, 2, nil, nil, false, false) Wait(10) @@ -117,6 +244,13 @@ RegisterNetEvent('polygun:runlaser', function() laserEnabled = not laserEnabled if not laserEnabled then laserEndPoint = nil + if DoesEntityExist(ENTITY) then + DeleteEntity(ENTITY) + end + destoryZone() + -- If the vehicle does exist, delete the vehicle entity from the game world. + + else drawLaser() end From f1083decc92abe6b7956d016fe81224a51e38e18 Mon Sep 17 00:00:00 2001 From: suryabhaiin <54040750+suryabhaiin@users.noreply.github.com> Date: Sun, 17 Mar 2024 10:05:07 +0530 Subject: [PATCH 04/10] Create Zone At point Create Zone At point --- client/laser.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/laser.lua b/client/laser.lua index 976142e..2220ed6 100644 --- a/client/laser.lua +++ b/client/laser.lua @@ -120,7 +120,7 @@ end -- Function to draw the laser effect function drawLaser() local playerPed = PlayerPedId() - lib.showTextUI("COPY : [E] vector3 | [Q] vector4 | [F] coords | [R] Json | [H] Heading | [G] Add Zone | [X] Save Zone", {position = 'top-center'}) + lib.showTextUI("CONTROLS : [E] vector3 | [Q] vector4 | [F] coords | [R] Json | [H] Heading | [G] Add Zone | [X] Save Zone", {position = 'top-center'}) while laserEnabled do local color = { r = 255, g = 255, b = 255, a = 200 } local position = GetEntityCoords(playerPed) From 097c65620d1ef2737d7cd45f700527ccf986e8a2 Mon Sep 17 00:00:00 2001 From: suryabhaiin <54040750+suryabhaiin@users.noreply.github.com> Date: Sun, 17 Mar 2024 10:21:31 +0530 Subject: [PATCH 05/10] create zones createzone at laser point coordinate --- client/laser.lua | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/client/laser.lua b/client/laser.lua index 2220ed6..4c731a9 100644 --- a/client/laser.lua +++ b/client/laser.lua @@ -120,7 +120,7 @@ end -- Function to draw the laser effect function drawLaser() local playerPed = PlayerPedId() - lib.showTextUI("CONTROLS : [E] vector3 | [Q] vector4 | [F] coords | [R] Json | [H] Heading | [G] Add Zone | [X] Save Zone", {position = 'top-center'}) + lib.showTextUI("CONTROLS : [N] vector2 | [E] vector3 | [Q] vector4 | [F] coords | [R] Json | [H] Heading | [G] Add Zone | [X] Save Zone", {position = 'top-center'}) while laserEnabled do local color = { r = 255, g = 255, b = 255, a = 200 } local position = GetEntityCoords(playerPed) @@ -144,7 +144,7 @@ function drawLaser() laserEndPoint = string.format('vector3(%s, %s, %s)', x, y, z) lib.setClipboard(laserEndPoint) lib.notify({ - title = 'Vector3 Copied', + title = 'Vector 3 Copy', duration = 7500, description = laserEndPoint, type = 'success' @@ -154,7 +154,19 @@ function drawLaser() laserEndPoint = string.format('vector4(%s, %s, %s, %s)', x, y, z, w) lib.setClipboard(laserEndPoint) lib.notify({ - title = 'Vector3 Copied', + title = 'Vector 4 Copy', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + end + + if IsControlJustReleased(0, 306) then --N Copy Coords + + laserEndPoint = string.format('vector2(%s, %s)', x, y) + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Vector 2 Copy', duration = 7500, description = laserEndPoint, type = 'success' @@ -165,7 +177,7 @@ function drawLaser() laserEndPoint = string.format('{x = %s, y = %s, z = %s, w = %s)', x, y, z, w) lib.setClipboard(laserEndPoint) lib.notify({ - title = 'Vector3 Copied', + title = 'Json Copy', duration = 7500, description = laserEndPoint, type = 'success' @@ -175,7 +187,7 @@ function drawLaser() laserEndPoint = string.format('%s', w) lib.setClipboard(laserEndPoint) lib.notify({ - title = 'Heading Copied', + title = 'Heading Copy', duration = 7500, description = laserEndPoint, type = 'success' @@ -188,7 +200,7 @@ function drawLaser() laserEndPoint = string.format('%s, %s, %s', x, y, z) lib.setClipboard(laserEndPoint) lib.notify({ - title = 'Coordinate Copied', + title = 'Coordinate Copy', duration = 7500, description = laserEndPoint, type = 'success' From c2f865ca5eb6102f1330dca17d8f1596714d3a81 Mon Sep 17 00:00:00 2001 From: suryabhaiin <54040750+suryabhaiin@users.noreply.github.com> Date: Sun, 17 Mar 2024 11:31:22 +0530 Subject: [PATCH 06/10] Spell correction Spell correction --- client/laser.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/client/laser.lua b/client/laser.lua index 4c731a9..afbc5cd 100644 --- a/client/laser.lua +++ b/client/laser.lua @@ -73,14 +73,13 @@ local function drawEntityZone() end function createEntity() - local input = lib.inputDialog('Dialog title', { - {type = 'input', label = 'Zone Name', description = 'Enter Zone name', required = true, min = 4, max = 16}, - {type = 'number', label = 'Width X', description = 'Enter width size', required = true, icon = 'hashtag'}, - {type = 'number', label = 'Height Y', description = 'Enter height size', required = true, icon = 'hashtag'}, - {type = 'number', label = 'Height Z', description = 'Enter height for Z', required = true, icon = 'hashtag'}, + local input = lib.inputDialog('Create Zone', { + {type = 'input', label = 'Zone Name', description = 'Enter Zone name', required = true, min = 4, max = 16, default = "polyzone_"..tostring(math.random(1111,9999))}, + {type = 'number', label = 'Width X', description = 'Enter width size', required = true, icon = 'hashtag', default = 2}, + {type = 'number', label = 'Height Y', description = 'Enter height size', required = true, icon = 'hashtag', default = 2}, + {type = 'number', label = 'Height Z', description = 'Enter height for Z', required = true, icon = 'hashtag', default = 2}, }) if not input then return end - print(json.encode(input), input[1], input[2]) local modelName = "prop_parking_sign_1" NAME = input[1] SCALEX = input[2] @@ -95,6 +94,9 @@ function createEntity() end ENTITY = CreateObject(modelName, laserEndPoint.x, laserEndPoint.y, laserEndPoint.z, true, true, true) SetEntityHeading(ENTITY, HEADING) + SetEntityAlpha(ENTITY, 0, false) + FreezeEntityPosition(ENTITY, true) + SetEntityCompletelyDisableCollision(ENTITY, false) Wait(100) drawEntityZone() end From a66f8c854c5be35a3682d4022b716477d498e1c4 Mon Sep 17 00:00:00 2001 From: suryabhaiin <54040750+suryabhaiin@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:07:08 +0530 Subject: [PATCH 07/10] Error fix Error fix --- client/laser.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/client/laser.lua b/client/laser.lua index afbc5cd..d7b869a 100644 --- a/client/laser.lua +++ b/client/laser.lua @@ -64,12 +64,14 @@ end local function drawEntityZone() destoryZone() - ZONE = EntityZone:Create(ENTITY, { - name = NAME, - debugPoly = true, - useZ = true, - scale = scale or { SCALEX, SCALEY, SCALEZ } - }) + if DoesEntityExist(ENTITY) then + ZONE = EntityZone:Create(ENTITY, { + name = NAME, + debugPoly = true, + useZ = true, + scale = scale or { SCALEX, SCALEY, SCALEZ } + }) + end end function createEntity() @@ -195,6 +197,8 @@ function drawLaser() type = 'success' }) end + + if IsControlJustReleased(0, 75) then -- Copy Coords without vetor local x = roundcord(coords.x, 2) local y = roundcord(coords.y, 2) From 460b1877f2bff703b5f3ea6fb9b660515a9f3de5 Mon Sep 17 00:00:00 2001 From: suryabhaiin <54040750+suryabhaiin@users.noreply.github.com> Date: Mon, 18 Mar 2024 14:08:43 +0530 Subject: [PATCH 08/10] Laser and Polygun command merged Laser and Polygun command merged --- README.md | 16 +- client/client.lua | 370 ++++++++++++++++++++++++++++++++++++---------- client/laser.lua | 275 ---------------------------------- shared/config.lua | 2 +- zones.txt | 0 5 files changed, 309 insertions(+), 354 deletions(-) delete mode 100644 client/laser.lua create mode 100644 zones.txt diff --git a/README.md b/README.md index d8a32ba..01198b4 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,18 @@ Easily create polyzones around objects and save for configuring - **Right/Left Arrows**: Scale Y - **Page Up/Down**: Scale Z -4) Press `E` (or use `/polygunsave`) to save it to the `zones.txt` file inside the resource +# Controls -5) Enable only coordinate copy from laser point `/plaser` +4) `X` to save it to the `zones.txt` file inside the resource + +5) `N` copy Vector2 + +6) `E` copy Vector3 + +7) `Q` Copy vectory4 + +8) `F` copy only coordinates (x, y, z) format + +9) `R` copy cords in json format + +10) `G` Add zone at laser/line pointed location \ No newline at end of file diff --git a/client/client.lua b/client/client.lua index c0d7500..645ecf5 100644 --- a/client/client.lua +++ b/client/client.lua @@ -1,13 +1,46 @@ -local RESULT, ENTITY, NAME, COORDS, PREVIOUS, ZONE, PREVIOUSZONE, SCALEX, SCALEY, SCALEZ - +local RESULT, HEADING, ENTITY, NAME, COORDS, PREVIOUS, ZONE, PREVIOUSZONE, SCALEX, SCALEY, SCALEZ +local laserEnabled = false +local laserEndPoint = nil local hashes_file = LoadResourceFile(GetCurrentResourceName(), "hashes.json") local hashes = json.decode(hashes_file) - +lib.hideTextUI() local function round(num, numDecimalPlaces) local mult = 10 ^ (numDecimalPlaces or 0) return math.floor(num * mult + 0.5) / mult end +local RotationToDirection = function(rotation) + local adjustedRotation = { + x = (math.pi / 180) * rotation.x, + y = (math.pi / 180) * rotation.y, + z = (math.pi / 180) * rotation.z + } + local direction = { + x = -math.sin(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)), + y = math.cos(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)), + z = math.sin(adjustedRotation.x) + } + return direction +end +local RayCastGamePlayCamera = function(distance) + -- Checks to see if the Gameplay Cam is Rendering or another is rendering (no clip functionality) + local currentRenderingCam = false + if not IsGameplayCamRendering() then + currentRenderingCam = GetRenderingCam() + end + + local cameraRotation = not currentRenderingCam and GetGameplayCamRot() or GetCamRot(currentRenderingCam, 2) + local cameraCoord = not currentRenderingCam and GetGameplayCamCoord() or GetCamCoord(currentRenderingCam) + local direction = RotationToDirection(cameraRotation) + local destination = { + x = cameraCoord.x + direction.x * distance, + y = cameraCoord.y + direction.y * distance, + z = cameraCoord.z + direction.z * distance + } + local _, b, c, _, e = GetShapeTestResult(StartShapeTestRay(cameraCoord.x, cameraCoord.y, cameraCoord.z, destination.x, destination.y, destination.z, -1, PlayerPedId(), 0)) + return b, c, e +end + local function parseBox(zone) return "{\n" @@ -16,10 +49,10 @@ local function parseBox(zone) "vector3(" .. tostring(round(zone.center.x, 2)) .. ", " .. tostring(round(zone.center.y, 2)) .. ", " .. tostring(round(zone.center.z, 2)) .. "),\n" - .. "\tlength = " .. tostring(zone.length) .. ",\n" - .. "\twidth = " .. tostring(zone.width) .. ",\n" + .. "\tlength = " .. tostring(SCALEX) .. ",\n" + .. "\twidth = " .. tostring(SCALEY) .. ",\n" .. "\tname = \"" .. zone.name .. "\",\n" - .. "\theading = " .. zone.offsetRot .. ",\n" + .. "\theading = " .. tostring(HEADING) .. ",\n" .. "\tminZ = " .. tostring(round(zone.minZ, 2)) .. ",\n" .. "\tmaxZ = " .. tostring(round(zone.maxZ, 2)) .. ",\n" .. "}\n" @@ -39,29 +72,72 @@ local function drawEntityZone() }) end -RegisterCommand('polygunsave', function() - if not Config.loopOn or not ZONE or ZONE == PREVIOUSZONE then return end - local text = parseBox(ZONE) - if Config.clipboard then lib.setClipboard(text) end - TriggerServerEvent('polygun:save', ZONE, text) - lib.notify({ - title = 'Box Zone Saved', - duration = 7500, - description = 'Check zones.txt inside the polygun resource', - type = 'success' +function createEntity() + local input = lib.inputDialog('Create Zone', { + {type = 'input', label = 'Zone Name', description = 'Enter Zone name', required = true, min = 4, max = 16, default = "polyzone_"..tostring(math.random(1111,9999))}, + {type = 'number', label = 'Width X', description = 'Enter width size', required = true, icon = 'hashtag', default = 2}, + {type = 'number', label = 'Height Y', description = 'Enter height size', required = true, icon = 'hashtag', default = 2}, + {type = 'number', label = 'Height Z', description = 'Enter height for Z', required = true, icon = 'hashtag', default = 2}, }) - PREVIOUSZONE = ZONE -end) + if not input then return end + local modelName = "prop_parking_sign_1" + NAME = input[1] + SCALEX = input[2] + SCALEY = input[3] + SCALEZ = input[4] + if DoesEntityExist(ENTITY) then + if GetEntityModel(entity) == GetHashKey("prop_parking_sign_1") then + DeleteEntity(ENTITY) + else + ENTITY = nil + end + end + RequestModel(modelName) + while not HasModelLoaded(modelName) do + Wait(500) + end + ENTITY = CreateObject(modelName, laserEndPoint.x, laserEndPoint.y, laserEndPoint.z, true, true, true) + SetEntityHeading(ENTITY, HEADING) + SetEntityAlpha(ENTITY, 0, false) + FreezeEntityPosition(ENTITY, true) + SetEntityCompletelyDisableCollision(ENTITY, false) + Wait(100) + drawEntityZone() +end -RegisterKeyMapping('polygunsave', 'Save selected polyzone', 'keyboard', Config.defaultSaveKey) +function saveZone() + if not Config.loopOn or not ZONE or ZONE == PREVIOUSZONE then return end + PREVIOUSZONE = ZONE + if ZONE then + local text = parseBox(ZONE) + if Config.clipboard then lib.setClipboard(text) end + TriggerServerEvent('polygun:save', ZONE, text) + lib.notify({ + title = 'Box Zone Saved', + duration = 7500, + description = 'Check zones.txt inside the polygun resource', + type = 'success' + }) + if laserEnabled then + if DoesEntityExist(ENTITY) then + DeleteEntity(ENTITY) + end + end + destoryZone() + Wait(300) + RESULT = nil + laserEnabled = false + end +end --- Thread that makes everything happen. -Citizen.CreateThread(function() -- Create the thread. +CreateThread(function() -- Create the thread. while true do -- Loop it infinitely. - local pause = 250 -- If infos are off, set loop to every 250ms. Eats less resources. + local pause = 250 + local player = PlayerId() + local playerPed = PlayerPedId() + -- If infos are off, set loop to every 250ms. Eats less resources. if Config.loopOn then -- If the info is on then... pause = 5 -- Only loop every 5ms (equivalent of 200fps). - local player = PlayerId() if IsPlayerFreeAiming(player) then -- If the player is free-aiming (update texts)... local start = GetPedBoneCoords(PlayerPedId(), 57005, 0.0, 0.0, 0.0) local result, entity = GetEntityPlayerIsFreeAimingAt(player) -- Get what the player is aiming at. This isn't actually the function, that's below the thread. @@ -76,65 +152,195 @@ Citizen.CreateThread(function() -- Create the t local finish = GetWorldCoordFromScreenCoord(0.5, 0.5) DrawLine(start.x, start.y, start.z, finish.x, finish.y, finish.z, 0, 255, 0, 255) end - end - if RESULT then - local heading = GetEntityHeading(ENTITY) - local model = GetEntityModel(ENTITY) - NAME = hashes[tostring(model)] or 'unknown' - if Config.debugText then - DrawInfos("Coordinates: " .. COORDS, "Heading: " .. heading, "Hash: " .. model, "Name: " .. NAME) - end - if ENTITY ~= PREVIOUS then - SCALEX = 1.0 - SCALEY = 1.0 - SCALEZ = 1.0 - drawEntityZone() - PREVIOUS = ENTITY - end - if IsControlJustPressed(0, 241) or IsDisabledControlPressed(1, 241) then -- Scroll Up - SCALEX = SCALEX + Config.addX - SCALEY = SCALEY + Config.addY - SCALEZ = SCALEZ + Config.addZ - drawEntityZone() - end - if IsControlJustPressed(0, 242) or IsDisabledControlPressed(1, 242) then -- Scroll down - SCALEX = SCALEX - Config.subX - SCALEY = SCALEY - Config.subY - SCALEZ = SCALEZ - Config.subZ - drawEntityZone() - end + else + if RESULT then + local heading = GetEntityHeading(ENTITY) + local model = GetEntityModel(ENTITY) + NAME = hashes[tostring(model)] or 'unknown' + if Config.debugText then + DrawInfos("Coordinates: " .. COORDS, "Heading: " .. heading, "Hash: " .. model, "Name: " .. NAME) + end + HEADING =heading + if ENTITY ~= PREVIOUS then + SCALEX = 1.0 + SCALEY = 1.0 + SCALEZ = 1.0 + drawEntityZone() + PREVIOUS = ENTITY + end + if IsControlJustPressed(0, 241) or IsDisabledControlPressed(1, 241) then -- Scroll Up + SCALEX = SCALEX + Config.addX + SCALEY = SCALEY + Config.addY + SCALEZ = SCALEZ + Config.addZ + drawEntityZone() + end + if IsControlJustPressed(0, 242) or IsDisabledControlPressed(1, 242) then -- Scroll down + SCALEX = SCALEX - Config.subX + SCALEY = SCALEY - Config.subY + SCALEZ = SCALEZ - Config.subZ + drawEntityZone() + end - if IsControlPressed(1, Config.addXControl) or IsDisabledControlPressed(1, Config.addXControl) then -- Up Arrow - SCALEX = SCALEX + Config.addX - drawEntityZone() - end - if IsControlPressed(1, Config.subXControl) or IsDisabledControlPressed(1, Config.subXControl) then -- Down Arrow - SCALEX = SCALEX - Config.subZ - drawEntityZone() - end + if IsControlPressed(1, Config.addXControl) or IsDisabledControlPressed(1, Config.addXControl) then -- Up Arrow + SCALEX = SCALEX + Config.addX + drawEntityZone() + end + if IsControlPressed(1, Config.subXControl) or IsDisabledControlPressed(1, Config.subXControl) then -- Down Arrow + SCALEX = SCALEX - Config.subZ + drawEntityZone() + end - if IsControlPressed(1, Config.subYControl) or IsDisabledControlPressed(1, Config.subYControl) then -- Left Arrow - SCALEY = SCALEY - Config.subY - drawEntityZone() - end - if IsControlPressed(1, Config.addYControl) or IsDisabledControlPressed(1, Config.addYControl) then -- Right Arrow - SCALEY = SCALEY + Config.addY - drawEntityZone() - end + if IsControlPressed(1, Config.subYControl) or IsDisabledControlPressed(1, Config.subYControl) then -- Left Arrow + SCALEY = SCALEY - Config.subY + drawEntityZone() + end + if IsControlPressed(1, Config.addYControl) or IsDisabledControlPressed(1, Config.addYControl) then -- Right Arrow + SCALEY = SCALEY + Config.addY + drawEntityZone() + end + + if IsControlPressed(1, Config.addZControl) or IsDisabledControlPressed(1, Config.addZControl) then -- Page Up + SCALEZ = SCALEZ + Config.addZ + drawEntityZone() + end + if IsControlPressed(1, Config.subZControl) or IsDisabledControlPressed(1, Config.subZControl) then -- Page Down + SCALEZ = SCALEZ - Config.subZ + drawEntityZone() + end + else + local color = { r = 255, g = 255, b = 255, a = 200 } + local position = GetEntityCoords(playerPed) + local hit, coords, entity = RayCastGamePlayCamera(1000.0) + local heading = GetEntityHeading(GetPlayerPed(-1)) + local x = round(coords.x, 2) + local y = round(coords.y, 2) + local z = round(coords.z, 2) + local w = round(heading, 2) + HEADING = w + if IsControlJustReleased(0, 58) then -- G add zone + laserEndPoint = coords + createEntity() + Wait(1000) + end + if IsControlJustReleased(0, 51) then -- Copy Vector3 Coords + laserEndPoint = string.format('vector3(%s, %s, %s)', x, y, z) + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Vector 3 Copy', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + end + if IsControlJustReleased(0, 52) then -- Copy Vector4 Coords + laserEndPoint = string.format('vector4(%s, %s, %s, %s)', x, y, z, w) + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Vector 4 Copy', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + end + + if IsControlJustReleased(0, 306) then --N Copy Coords + + laserEndPoint = string.format('vector2(%s, %s)', x, y) + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Vector 2 Copy', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + end + if IsControlJustReleased(0, 45) then -- Copy Coords In json + + laserEndPoint = string.format('{x = %s, y = %s, z = %s, w = %s)', x, y, z, w) + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Json Copy', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + end + if IsControlJustReleased(0, 74) then -- Copy Heading + laserEndPoint = string.format('%s', w) + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Heading Copy', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + end - if IsControlPressed(1, Config.addZControl) or IsDisabledControlPressed(1, Config.addZControl) then -- Page Up - SCALEZ = SCALEZ + Config.addZ - drawEntityZone() + + if IsControlJustReleased(0, 75) then -- Copy Coords without vetor + local x = round(coords.x, 2) + local y = round(coords.y, 2) + local z = round(coords.z, 2) + laserEndPoint = string.format('%s, %s, %s', x, y, z) + lib.setClipboard(laserEndPoint) + lib.notify({ + title = 'Coordinate Copy', + duration = 7500, + description = laserEndPoint, + type = 'success' + }) + end + if IsControlJustPressed(0, 241) or IsDisabledControlPressed(1, 241) then -- Scroll Up + SCALEX = SCALEX + Config.addX + SCALEY = SCALEY + Config.addY + SCALEZ = SCALEZ + Config.addZ + drawEntityZone() + end + if IsControlJustPressed(0, 242) or IsDisabledControlPressed(1, 242) then -- Scroll down + SCALEX = SCALEX - Config.subX + SCALEY = SCALEY - Config.subY + SCALEZ = SCALEZ - Config.subZ + drawEntityZone() + end + + if IsControlPressed(1, Config.addXControl) or IsDisabledControlPressed(1, Config.addXControl) then -- Up Arrow + SCALEX = SCALEX + Config.addX + drawEntityZone() + end + if IsControlPressed(1, Config.subXControl) or IsDisabledControlPressed(1, Config.subXControl) then -- Down Arrow + SCALEX = SCALEX - Config.subZ + drawEntityZone() + end + + if IsControlPressed(1, Config.subYControl) or IsDisabledControlPressed(1, Config.subYControl) then -- Left Arrow + SCALEY = SCALEY - Config.subY + drawEntityZone() + end + if IsControlPressed(1, Config.addYControl) or IsDisabledControlPressed(1, Config.addYControl) then -- Right Arrow + SCALEY = SCALEY + Config.addY + drawEntityZone() + end + + if IsControlPressed(1, Config.addZControl) or IsDisabledControlPressed(1, Config.addZControl) then -- Page Up + SCALEZ = SCALEZ + Config.addZ + drawEntityZone() + end + if IsControlPressed(1, Config.subZControl) or IsDisabledControlPressed(1, Config.subZControl) then -- Page Down + SCALEZ = SCALEZ - Config.subZ + drawEntityZone() + end + DrawLine(position.x, position.y, position.z, coords.x, coords.y, coords.z, color.r, color.g, color.b, color.a) + DrawMarker(28, coords.x, coords.y, coords.z, 0.0, 0.0, 0.0, 0.0, 180.0, 0.0, 0.1, 0.1, 0.1, color.r, color.g, color.b, color.a, false, true, 2, nil, nil, false, false) end - if IsControlPressed(1, Config.subZControl) or IsDisabledControlPressed(1, Config.subZControl) then -- Page Down - SCALEZ = SCALEZ - Config.subZ - drawEntityZone() + if IsControlJustReleased(0, 73) then -- Xsave zone + saveZone() + Wait(1000) end end - end -- Info is off, don't need to do anything. - Citizen.Wait(pause) -- Now wait the specified time. - end -- End (stop looping). -end) -- Endind the entire thread here. + end + Wait(pause) + end +end) -- Ends the function. -- Function to draw the text. @@ -161,6 +367,14 @@ end -- Creating the function to toggle the info. ToggleInfos = function() -- "ToggleInfos" is a function Config.loopOn = not Config.loopOn -- Switch them around + if laserEnabled then + laserEndPoint = nil + if DoesEntityExist(ENTITY) then + DeleteEntity(ENTITY) + end + laserEnabled = false + destoryZone() + end end -- Ending the function here. RegisterNetEvent('polygun:runpolygun', function() @@ -173,5 +387,9 @@ RegisterNetEvent('polygun:runpolygun', function() description = 'Get Gun In hand and aim to entity', type = 'success' }) + RESULT = nil + lib.showTextUI("CONTROLS : [N] vector2 | [E] vector3 | [Q] vector4 | [F] coords | [R] Json | [H] Heading | [G] Add Zone | [X] Save Zone", {position = 'top-center'}) + else + lib.hideTextUI() end end) \ No newline at end of file diff --git a/client/laser.lua b/client/laser.lua deleted file mode 100644 index d7b869a..0000000 --- a/client/laser.lua +++ /dev/null @@ -1,275 +0,0 @@ -local RESULT, HEADING, ENTITY, NAME, COORDS, PREVIOUS, ZONE, PREVIOUSZONE, SCALEX, SCALEY, SCALEZ -local laserEnabled = false -local laserEndPoint = nil -lib.hideTextUI() -local function roundcord(value, numDecimalPlaces) - if not numDecimalPlaces then return math.floor(value + 0.5) end - local power = 10 ^ numDecimalPlaces - return math.floor((value * power) + 0.5) / (power) -end - -local RotationToDirection = function(rotation) - local adjustedRotation = { - x = (math.pi / 180) * rotation.x, - y = (math.pi / 180) * rotation.y, - z = (math.pi / 180) * rotation.z - } - local direction = { - x = -math.sin(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)), - y = math.cos(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)), - z = math.sin(adjustedRotation.x) - } - return direction -end -local RayCastGamePlayCamera = function(distance) - -- Checks to see if the Gameplay Cam is Rendering or another is rendering (no clip functionality) - local currentRenderingCam = false - if not IsGameplayCamRendering() then - currentRenderingCam = GetRenderingCam() - end - - local cameraRotation = not currentRenderingCam and GetGameplayCamRot() or GetCamRot(currentRenderingCam, 2) - local cameraCoord = not currentRenderingCam and GetGameplayCamCoord() or GetCamCoord(currentRenderingCam) - local direction = RotationToDirection(cameraRotation) - local destination = { - x = cameraCoord.x + direction.x * distance, - y = cameraCoord.y + direction.y * distance, - z = cameraCoord.z + direction.z * distance - } - local _, b, c, _, e = GetShapeTestResult(StartShapeTestRay(cameraCoord.x, cameraCoord.y, cameraCoord.z, destination.x, destination.y, destination.z, -1, PlayerPedId(), 0)) - return b, c, e -end - - -local function parseBox(zone) - return - "{\n" - .. - "\tcoords = " .. - "vector3(" .. - tostring(roundcord(zone.center.x, 2)) .. - ", " .. tostring(roundcord(zone.center.y, 2)) .. ", " .. tostring(roundcord(zone.center.z, 2)) .. "),\n" - .. "\tlength = " .. tostring(SCALEX) .. ",\n" - .. "\twidth = " .. tostring(SCALEY) .. ",\n" - .. "\tname = \"" .. zone.name .. "\",\n" - .. "\theading = " .. tostring(HEADING) .. ",\n" - .. "\tminZ = " .. tostring(roundcord(zone.minZ, 2)) .. ",\n" - .. "\tmaxZ = " .. tostring(roundcord(zone.maxZ, 2)) .. ",\n" - .. "}\n" -end - -local function destoryZone() - if ZONE then ZONE:destroy() end -end - -local function drawEntityZone() - destoryZone() - if DoesEntityExist(ENTITY) then - ZONE = EntityZone:Create(ENTITY, { - name = NAME, - debugPoly = true, - useZ = true, - scale = scale or { SCALEX, SCALEY, SCALEZ } - }) - end -end - -function createEntity() - local input = lib.inputDialog('Create Zone', { - {type = 'input', label = 'Zone Name', description = 'Enter Zone name', required = true, min = 4, max = 16, default = "polyzone_"..tostring(math.random(1111,9999))}, - {type = 'number', label = 'Width X', description = 'Enter width size', required = true, icon = 'hashtag', default = 2}, - {type = 'number', label = 'Height Y', description = 'Enter height size', required = true, icon = 'hashtag', default = 2}, - {type = 'number', label = 'Height Z', description = 'Enter height for Z', required = true, icon = 'hashtag', default = 2}, - }) - if not input then return end - local modelName = "prop_parking_sign_1" - NAME = input[1] - SCALEX = input[2] - SCALEY = input[3] - SCALEZ = input[4] - if DoesEntityExist(ENTITY) then - DeleteEntity(ENTITY) - end - RequestModel(modelName) - while not HasModelLoaded(modelName) do - Wait(500) - end - ENTITY = CreateObject(modelName, laserEndPoint.x, laserEndPoint.y, laserEndPoint.z, true, true, true) - SetEntityHeading(ENTITY, HEADING) - SetEntityAlpha(ENTITY, 0, false) - FreezeEntityPosition(ENTITY, true) - SetEntityCompletelyDisableCollision(ENTITY, false) - Wait(100) - drawEntityZone() -end - -function saveZone() - if ZONE then - local text = parseBox(ZONE) - if Config.clipboard then lib.setClipboard(text) end - TriggerServerEvent('polygun:save', ZONE, text) - lib.notify({ - title = 'Box Zone Saved', - duration = 7500, - description = 'Check zones.txt inside the polygun resource', - type = 'success' - }) - if DoesEntityExist(ENTITY) then - DeleteEntity(ENTITY) - end - destoryZone() - end -end - --- Function to draw the laser effect -function drawLaser() - local playerPed = PlayerPedId() - lib.showTextUI("CONTROLS : [N] vector2 | [E] vector3 | [Q] vector4 | [F] coords | [R] Json | [H] Heading | [G] Add Zone | [X] Save Zone", {position = 'top-center'}) - while laserEnabled do - local color = { r = 255, g = 255, b = 255, a = 200 } - local position = GetEntityCoords(playerPed) - local hit, coords, entity = RayCastGamePlayCamera(1000.0) - local heading = GetEntityHeading(GetPlayerPed(-1)) - local x = roundcord(coords.x, 2) - local y = roundcord(coords.y, 2) - local z = roundcord(coords.z, 2) - local w = roundcord(heading, 2) - HEADING = w - if IsControlJustReleased(0, 73) then --save zone - saveZone() - Wait(1000) - end - if IsControlJustReleased(0, 58) then -- G add zone - laserEndPoint = coords - createEntity() - Wait(1000) - end - if IsControlJustReleased(0, 51) then -- Copy Vector3 Coords - laserEndPoint = string.format('vector3(%s, %s, %s)', x, y, z) - lib.setClipboard(laserEndPoint) - lib.notify({ - title = 'Vector 3 Copy', - duration = 7500, - description = laserEndPoint, - type = 'success' - }) - end - if IsControlJustReleased(0, 52) then -- Copy Vector4 Coords - laserEndPoint = string.format('vector4(%s, %s, %s, %s)', x, y, z, w) - lib.setClipboard(laserEndPoint) - lib.notify({ - title = 'Vector 4 Copy', - duration = 7500, - description = laserEndPoint, - type = 'success' - }) - end - - if IsControlJustReleased(0, 306) then --N Copy Coords - - laserEndPoint = string.format('vector2(%s, %s)', x, y) - lib.setClipboard(laserEndPoint) - lib.notify({ - title = 'Vector 2 Copy', - duration = 7500, - description = laserEndPoint, - type = 'success' - }) - end - if IsControlJustReleased(0, 45) then -- Copy Coords In json - - laserEndPoint = string.format('{x = %s, y = %s, z = %s, w = %s)', x, y, z, w) - lib.setClipboard(laserEndPoint) - lib.notify({ - title = 'Json Copy', - duration = 7500, - description = laserEndPoint, - type = 'success' - }) - end - if IsControlJustReleased(0, 74) then -- Copy Heading - laserEndPoint = string.format('%s', w) - lib.setClipboard(laserEndPoint) - lib.notify({ - title = 'Heading Copy', - duration = 7500, - description = laserEndPoint, - type = 'success' - }) - end - - - if IsControlJustReleased(0, 75) then -- Copy Coords without vetor - local x = roundcord(coords.x, 2) - local y = roundcord(coords.y, 2) - local z = roundcord(coords.z, 2) - laserEndPoint = string.format('%s, %s, %s', x, y, z) - lib.setClipboard(laserEndPoint) - lib.notify({ - title = 'Coordinate Copy', - duration = 7500, - description = laserEndPoint, - type = 'success' - }) - end - if IsControlJustPressed(0, 241) or IsDisabledControlPressed(1, 241) then -- Scroll Up - SCALEX = SCALEX + Config.addX - SCALEY = SCALEY + Config.addY - SCALEZ = SCALEZ + Config.addZ - drawEntityZone() - end - if IsControlJustPressed(0, 242) or IsDisabledControlPressed(1, 242) then -- Scroll down - SCALEX = SCALEX - Config.subX - SCALEY = SCALEY - Config.subY - SCALEZ = SCALEZ - Config.subZ - drawEntityZone() - end - - if IsControlPressed(1, Config.addXControl) or IsDisabledControlPressed(1, Config.addXControl) then -- Up Arrow - SCALEX = SCALEX + Config.addX - drawEntityZone() - end - if IsControlPressed(1, Config.subXControl) or IsDisabledControlPressed(1, Config.subXControl) then -- Down Arrow - SCALEX = SCALEX - Config.subZ - drawEntityZone() - end - - if IsControlPressed(1, Config.subYControl) or IsDisabledControlPressed(1, Config.subYControl) then -- Left Arrow - SCALEY = SCALEY - Config.subY - drawEntityZone() - end - if IsControlPressed(1, Config.addYControl) or IsDisabledControlPressed(1, Config.addYControl) then -- Right Arrow - SCALEY = SCALEY + Config.addY - drawEntityZone() - end - - if IsControlPressed(1, Config.addZControl) or IsDisabledControlPressed(1, Config.addZControl) then -- Page Up - SCALEZ = SCALEZ + Config.addZ - drawEntityZone() - end - if IsControlPressed(1, Config.subZControl) or IsDisabledControlPressed(1, Config.subZControl) then -- Page Down - SCALEZ = SCALEZ - Config.subZ - drawEntityZone() - end - DrawLine(position.x, position.y, position.z, coords.x, coords.y, coords.z, color.r, color.g, color.b, color.a) - DrawMarker(28, coords.x, coords.y, coords.z, 0.0, 0.0, 0.0, 0.0, 180.0, 0.0, 0.1, 0.1, 0.1, color.r, color.g, color.b, color.a, false, true, 2, nil, nil, false, false) - Wait(10) - end - lib.hideTextUI() -end - -RegisterNetEvent('polygun:runlaser', function() - laserEnabled = not laserEnabled - if not laserEnabled then - laserEndPoint = nil - if DoesEntityExist(ENTITY) then - DeleteEntity(ENTITY) - end - destoryZone() - -- If the vehicle does exist, delete the vehicle entity from the game world. - - - else - drawLaser() - end -end) \ No newline at end of file diff --git a/shared/config.lua b/shared/config.lua index 9deeec8..a60d2bf 100644 --- a/shared/config.lua +++ b/shared/config.lua @@ -2,7 +2,7 @@ Config = {} Config.loopOn = false -- true: enabled by default, false: disabled by default (use /polygun to toggle) -Config.defaultSaveKey = 'E' -- Keybind to save selected zone to `zones.txt` file +Config.defaultSaveKey = 'X' -- Keybind to save selected zone to `zones.txt` file Config.clipboard = true -- Copy to clipboard on save diff --git a/zones.txt b/zones.txt new file mode 100644 index 0000000..e69de29 From d556a890df09cc9d264ad43ae21e456f8414dbea Mon Sep 17 00:00:00 2001 From: suryabhaiin <54040750+suryabhaiin@users.noreply.github.com> Date: Mon, 18 Mar 2024 14:16:07 +0530 Subject: [PATCH 09/10] Laser and Polygun command merged Laser and Polygun command merged and one minor bug fix --- client/client.lua | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/client/client.lua b/client/client.lua index 645ecf5..f009d16 100644 --- a/client/client.lua +++ b/client/client.lua @@ -64,12 +64,14 @@ end local function drawEntityZone() destoryZone() - ZONE = EntityZone:Create(ENTITY, { - name = NAME, - debugPoly = true, - useZ = true, - scale = scale or { SCALEX, SCALEY, SCALEZ } - }) + if DoesEntityExist(ENTITY) then + ZONE = EntityZone:Create(ENTITY, { + name = NAME, + debugPoly = true, + useZ = true, + scale = scale or { SCALEX, SCALEY, SCALEZ } + }) + end end function createEntity() @@ -88,10 +90,9 @@ function createEntity() if DoesEntityExist(ENTITY) then if GetEntityModel(entity) == GetHashKey("prop_parking_sign_1") then DeleteEntity(ENTITY) - else - ENTITY = nil end end + ENTITY = nil RequestModel(modelName) while not HasModelLoaded(modelName) do Wait(500) @@ -123,6 +124,7 @@ function saveZone() DeleteEntity(ENTITY) end end + ENTITY = nil destoryZone() Wait(300) RESULT = nil @@ -276,7 +278,6 @@ CreateThread(function() -- Create the thread. }) end - if IsControlJustReleased(0, 75) then -- Copy Coords without vetor local x = round(coords.x, 2) local y = round(coords.y, 2) From 289f65c6b68a99a7c9658fdd855c43e7b28e8018 Mon Sep 17 00:00:00 2001 From: suryabhaiin <54040750+suryabhaiin@users.noreply.github.com> Date: Tue, 19 Mar 2024 09:36:54 +0530 Subject: [PATCH 10/10] Aim & Laser fix aim to add zone issue fix laser issue fix --- client/client.lua | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/client/client.lua b/client/client.lua index f009d16..4aaa88f 100644 --- a/client/client.lua +++ b/client/client.lua @@ -76,7 +76,7 @@ end function createEntity() local input = lib.inputDialog('Create Zone', { - {type = 'input', label = 'Zone Name', description = 'Enter Zone name', required = true, min = 4, max = 16, default = "polyzone_"..tostring(math.random(1111,9999))}, + {type = 'input', label = 'Zone Name', description = 'Enter Zone name', required = true, min = 4, max = 16, default = "boxzone_"..tostring(math.random(1111,9999))}, {type = 'number', label = 'Width X', description = 'Enter width size', required = true, icon = 'hashtag', default = 2}, {type = 'number', label = 'Height Y', description = 'Enter height size', required = true, icon = 'hashtag', default = 2}, {type = 'number', label = 'Height Z', description = 'Enter height for Z', required = true, icon = 'hashtag', default = 2}, @@ -124,12 +124,12 @@ function saveZone() DeleteEntity(ENTITY) end end - ENTITY = nil - destoryZone() - Wait(300) - RESULT = nil - laserEnabled = false end + ENTITY = nil + destoryZone() + Wait(300) + RESULT = nil + laserEnabled = false end CreateThread(function() -- Create the thread. @@ -141,20 +141,17 @@ CreateThread(function() -- Create the thread. if Config.loopOn then -- If the info is on then... pause = 5 -- Only loop every 5ms (equivalent of 200fps). if IsPlayerFreeAiming(player) then -- If the player is free-aiming (update texts)... + if RESULT then + RESULT = nil + end local start = GetPedBoneCoords(PlayerPedId(), 57005, 0.0, 0.0, 0.0) local result, entity = GetEntityPlayerIsFreeAimingAt(player) -- Get what the player is aiming at. This isn't actually the function, that's below the thread. if result then RESULT = result ENTITY = entity COORDS = GetEntityCoords(ENTITY) - if Config.debugAimLine then - DrawLine(start.x, start.y, start.z, COORDS.x, COORDS.y, COORDS.z, 0, 255, 0, 255) - end - elseif Config.debugAimLine then - local finish = GetWorldCoordFromScreenCoord(0.5, 0.5) - DrawLine(start.x, start.y, start.z, finish.x, finish.y, finish.z, 0, 255, 0, 255) end - else + end if RESULT then local heading = GetEntityHeading(ENTITY) local model = GetEntityModel(ENTITY) @@ -210,7 +207,7 @@ CreateThread(function() -- Create the thread. drawEntityZone() end else - local color = { r = 255, g = 255, b = 255, a = 200 } + local color = { r = 0, g = 255, b = 0, a = 200 } local position = GetEntityCoords(playerPed) local hit, coords, entity = RayCastGamePlayCamera(1000.0) local heading = GetEntityHeading(GetPlayerPed(-1)) @@ -337,7 +334,7 @@ CreateThread(function() -- Create the thread. saveZone() Wait(1000) end - end + end Wait(pause) end