From a30eb0027fd3b1abdcf41e3b619e9709dedcc8b0 Mon Sep 17 00:00:00 2001 From: DevX32 <60389339+DevX32@users.noreply.github.com> Date: Sat, 14 Oct 2023 09:17:37 +0545 Subject: [PATCH] Update admin.lua --- client/admin.lua | 121 ++++++++++++++++++----------------------------- 1 file changed, 46 insertions(+), 75 deletions(-) diff --git a/client/admin.lua b/client/admin.lua index e57b8d6..0156b5d 100644 --- a/client/admin.lua +++ b/client/admin.lua @@ -94,9 +94,8 @@ lib.registerMenu({ end end) ---- Needs cleanup local noClipEnabled = false -local ent +local ent = nil local noClipCam = nil local speed = 1.0 local maxSpeed = 32.0 @@ -123,32 +122,19 @@ function toggleNoclip() AttachCamToEntity(noClipCam, ent, 0.0, 0.0, 0.0, true) RenderScriptCams(true, false, 3000, true, false) - FreezeEntityPosition(ent, true) - SetEntityCollision(ent, false, false) - SetEntityAlpha(ent, 0, false) - SetPedCanRagdoll(ped, false) - SetEntityVisible(ent, false, false) - if not inVehicle then - ClearPedTasksImmediately(ped) - end - - if inVehicle then - FreezeEntityPosition(ped, true) - SetEntityCollision(ped, false, false) - SetEntityAlpha(ped, 0, false) - SetEntityVisible(ped, false, false) - end - - while noClipEnabled do - local _, fv = GetCamMatrix(noClipCam) - + local function adjustSpeed() if IsDisabledControlPressed(2, 17) then -- MWheelUp speed = math.min(speed + 0.1, maxSpeed) elseif IsDisabledControlPressed(2, 16) then -- MWheelDown speed = math.max(0.1, speed - 0.1) end + end + + while noClipEnabled do + local _, fv = GetCamMatrix(noClipCam) + adjustSpeed() - local multiplier = 1.0; + local multiplier = 1.0 if IsDisabledControlPressed(2, 209) then multiplier = 2.0 @@ -158,69 +144,49 @@ function toggleNoclip() multiplier = 0.25 end - -- Forward and Backward - if IsDisabledControlPressed(2, 32) then -- W - local setpos = GetEntityCoords(ent) + fv * (speed * multiplier) - SetEntityCoordsNoOffset(ent, setpos.x, setpos.y, setpos.z, false, false, false) - if not inVehicle then - SetEntityCoordsNoOffset(ped, setpos.x, setpos.y, setpos.z, false, false, false) - end - elseif IsDisabledControlPressed(2, 33) then -- S - local setpos = GetEntityCoords(ent) - fv * (speed * multiplier) - SetEntityCoordsNoOffset(ent, setpos.x, setpos.y, setpos.z, false, false, false) - if not inVehicle then - SetEntityCoordsNoOffset(ped, setpos.x, setpos.y, setpos.z, false, false, false) - end + local forwardMovement = vector3(0.0, 0.0, 0.0) + local horizontalMovement = vector2(0.0, 0.0) + local verticalMovement = 0.0 + + if IsDisabledControlPressed(2, 32) then + forwardMovement = fv * (speed * multiplier) + elseif IsDisabledControlPressed(2, 33) then + forwardMovement = -fv * (speed * multiplier) end - -- Left and Right - if IsDisabledControlPressed(2, 34) then -- A - local setpos = GetOffsetFromEntityInWorldCoords(ent, -speed * multiplier, 0.0, 0.0) - SetEntityCoordsNoOffset(ent, setpos.x, setpos.y, GetEntityCoords(ent).z, false, false, false) - if not inVehicle then - SetEntityCoordsNoOffset(ped, setpos.x, setpos.y, GetEntityCoords(ent).z, false, false, false) - end - elseif IsDisabledControlPressed(2, 35) then -- D - local setpos = GetOffsetFromEntityInWorldCoords(ent, speed * multiplier, 0.0, 0.0) - SetEntityCoordsNoOffset(ent, setpos.x, setpos.y, GetEntityCoords(ent).z, false, false, false) - if not inVehicle then - SetEntityCoordsNoOffset(ped, setpos.x, setpos.y, GetEntityCoords(ent).z, false, false, false) - end + if IsDisabledControlPressed(2, 34) then + horizontalMovement = vector2(-speed * multiplier, 0.0) + elseif IsDisabledControlPressed(2, 35) then + horizontalMovement = vector2(speed * multiplier, 0.0) end - -- Up and Down - if IsDisabledControlPressed(2, 38) then -- E - local setpos = GetOffsetFromEntityInWorldCoords(ent, 0.0, 0.0, multiplier * speed / 2) - SetEntityCoordsNoOffset(ent, setpos.x, setpos.y, setpos.z, false, false, false) - if not inVehicle then - SetEntityCoordsNoOffset(ped, setpos.x, setpos.y, setpos.z, false, false, false) - end + if IsDisabledControlPressed(2, 38) then + verticalMovement = multiplier * speed / 2 elseif IsDisabledControlPressed(2, 52) then - local setpos = GetOffsetFromEntityInWorldCoords(ent, 0.0, 0.0, multiplier * -speed / 2) -- Q - SetEntityCoordsNoOffset(ent, setpos.x, setpos.y, setpos.z, false, false, false) - if not inVehicle then - SetEntityCoordsNoOffset(ped, setpos.x, setpos.y, setpos.z, false, false, false) - end + verticalMovement = multiplier * -speed / 2 + end + + local setpos = GetEntityCoords(ent) + forwardMovement + vector3(horizontalMovement.x, horizontalMovement.y, verticalMovement) + SetEntityCoordsNoOffset(ent, setpos.x, setpos.y, setpos.z, false, false, false) + + if not inVehicle then + local pedPos = GetEntityCoords(ped) + SetEntityCoordsNoOffset(ped, setpos.x, setpos.y, pedPos.z, false, false, false) end local camrot = GetCamRot(noClipCam, 2) SetEntityHeading(ent, (360 + camrot.z) % 360.0) SetEntityVisible(ent, false, false) + if inVehicle then SetEntityVisible(ped, false, false) end - DisableControlAction(2, 32, true) - DisableControlAction(2, 33, true) - DisableControlAction(2, 34, true) - DisableControlAction(2, 35, true) - DisableControlAction(2, 36, true) - DisableControlAction(2, 12, true) - DisableControlAction(2, 13, true) - DisableControlAction(2, 14, true) - DisableControlAction(2, 15, true) - DisableControlAction(2, 16, true) - DisableControlAction(2, 17, true) + local controlActions = {32, 33, 34, 35, 36, 12, 13, 14, 15, 16, 17} + for _, controlAction in ipairs(controlActions) do + DisableControlAction(2, controlAction, true) + end + DisablePlayerFiring(cache.playerId, true) Wait(0) end @@ -253,33 +219,38 @@ function checkInputRotation() local axisX = GetDisabledControlNormal(0, 1) local axisY = GetDisabledControlNormal(0, 2) local sensitivity = GetProfileSetting(14) * 2 - if GetProfileSetting(15) == 0 --[[ Invert ]] then - -- this is default inverse + + if GetProfileSetting(15) == 0 then sensitivity = -sensitivity end - if (math.abs(axisX) > 0) or (math.abs(axisY) > 0) then + + if math.abs(axisX) > 0 or math.abs(axisY) > 0 then local rotation = GetCamRot(noClipCam, 2) local rotz = rotation.z + (axisX * sensitivity) local yValue = axisY * sensitivity local rotx = rotation.x + if rotx + yValue > minY and rotx + yValue < maxY then rotx = rotation.x + yValue end + SetCamRot(noClipCam, rotx, rotation.y, rotz, 2) end + Wait(0) end end) end RegisterNetEvent('qb-admin:client:noclip', function() - if GetInvokingResource() then return end -- Safety to make sure it is only called from the server + if GetInvokingResource() then return end toggleNoClipMode() end) function toggleNoClipMode() noClipEnabled = not noClipEnabled inputRotEnabled = noClipEnabled + if noClipEnabled and inputRotEnabled then toggleNoclip() checkInputRotation()