Skip to content

Commit

Permalink
Update admin.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
DevX32 authored Oct 14, 2023
1 parent cb48f03 commit a30eb00
Showing 1 changed file with 46 additions and 75 deletions.
121 changes: 46 additions & 75 deletions client/admin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a30eb00

Please sign in to comment.