Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noclip bugs fix #42

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 92 additions & 85 deletions client/admin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ lib.registerMenu({
end
end)

local noclipEnabled = false
local ent = nil
local noclipCam = nil
local noClipEnabled = false
local ent
local Invisible = nil
local noClipCam = nil
local speed = 1.0
local maxSpeed = 32.0
local minY, maxY = -150.0, 160.0
Expand All @@ -112,98 +113,106 @@ function toggleNoclip()
else
ent = cache.ped
end

local pos = GetEntityCoords(ent)
local rot = GetEntityRotation(ent)

noclipCam = CreateCamWithParams('DEFAULT_SCRIPTED_CAMERA', pos.x, pos.y, pos.z, 0.0, 0.0, rot.z, 75.0, true, 2)
AttachCamToEntity(noclipCam, ent, 0.0, 0.0, 0.0, true)
noClipCam = CreateCamWithParams('DEFAULT_SCRIPTED_CAMERA', pos, 0.0, 0.0, rot.z, 75.0, true, 2)
AttachCamToEntity(noClipCam, ent, 0.0, 0.0, 0.0, true)
RenderScriptCams(true, false, 3000, true, false)

local function adjustSpeed()
if IsDisabledControlPressed(2, 17) then -- MWheelUp
FreezeEntityPosition(ent, true)
SetEntityCollision(ent, false, false)
SetEntityAlpha(ent, 0)
SetPedCanRagdoll(cache.ped, false)
SetEntityVisible(ent, false)
if not inVehicle then
ClearPedTasksImmediately(cache.ped)
end
if inVehicle then
FreezeEntityPosition(cache.ped, true)
SetEntityCollision(cache.ped, false, false)
SetEntityAlpha(cache.ped, 0)
SetEntityVisible(cache.ped, false)
end
while noClipEnabled do
Wait(0)
local _, fv, _, _ = GetCamMatrix(noClipCam)
if IsDisabledControlPressed(2, 17) then
speed = math.min(speed + 0.1, maxSpeed)
elseif IsDisabledControlPressed(2, 16) then -- MWheelDown
elseif IsDisabledControlPressed(2, 16) then
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
elseif IsDisabledControlPressed(2, 19) then
multiplier = 4.0
elseif IsDisabledControlPressed(2, 36) then
multiplier = 0.25
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)
local setpos = GetEntityCoords(ent) + fv * (speed * multiplier)
SetEntityCoordsNoOffset(ent, setpos)
if not inVehicle then
SetEntityCoordsNoOffset(cache.ped, setpos)
end
elseif IsDisabledControlPressed(2, 33) then
forwardMovement = -fv * (speed * multiplier)
local setpos = GetEntityCoords(ent) - fv * (speed * multiplier)
SetEntityCoordsNoOffset(ent, setpos)
if not inVehicle then
SetEntityCoordsNoOffset(cache.ped, setpos)
end
end

if IsDisabledControlPressed(2, 34) then
horizontalMovement = vector2(-speed * multiplier, 0.0)
local setpos = GetOffsetFromEntityInWorldCoords(ent, -speed * multiplier, 0.0, 0.0)
SetEntityCoordsNoOffset(ent, setpos.x, setpos.y, GetEntityCoords(ent).z)
if not inVehicle then
SetEntityCoordsNoOffset(cache.ped, setpos.x, setpos.y, GetEntityCoords(ent).z)
end
elseif IsDisabledControlPressed(2, 35) then
horizontalMovement = vector2(speed * multiplier, 0.0)
local setpos = GetOffsetFromEntityInWorldCoords(ent, speed * multiplier, 0.0, 0.0)
SetEntityCoordsNoOffset(ent, setpos.x, setpos.y, GetEntityCoords(ent).z)
if not inVehicle then
SetEntityCoordsNoOffset(cache.ped, setpos.x, setpos.y, GetEntityCoords(ent).z)
end
end

if IsDisabledControlPressed(2, 38) then
verticalMovement = multiplier * speed / 2
if IsDisabledControlPressed(2, 22) then
local setpos = GetOffsetFromEntityInWorldCoords(ent, 0.0, 0.0, multiplier * speed / 2)
SetEntityCoordsNoOffset(ent, setpos)
if not inVehicle then
SetEntityCoordsNoOffset(cache.ped, setpos)
end
elseif IsDisabledControlPressed(2, 52) then
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(cache.ped)
SetEntityCoordsNoOffset(cache.ped, setpos.x, setpos.y, pedPos.z, false, false, false)
local setpos = GetOffsetFromEntityInWorldCoords(ent, 0.0, 0.0, multiplier * -speed / 2) -- Q
SetEntityCoordsNoOffset(ent, setpos)
if not inVehicle then
SetEntityCoordsNoOffset(cache.ped, setpos)
end
end

local camRot = GetCamRot(noclipCam, 2)
SetEntityHeading(ent, (360 + camRot.z) % 360.0)
SetEntityVisible(ent, false, false)

local camrot = GetCamRot(noClipCam, 2)
SetEntityHeading(ent, (360 + camrot.z) % 360.0)
SetEntityVisible(ent, false)
if inVehicle then
SetEntityVisible(cache.ped, false, false)
SetEntityVisible(cache.ped, false)
end

local controlActions = {32, 33, 34, 35, 36, 12, 13, 14, 15, 16, 17}
for _, controlAction in ipairs(controlActions) do
DisableControlAction(2, controlAction, true)
local disableControls = { 32, 33, 34, 35, 36, 12, 13, 14, 15, 16, 17 }
for _, control in ipairs(disableControls) do
DisableControlAction(2, control, true)
end

DisablePlayerFiring(cache.playerId, true)
Wait(0)
end

DestroyCam(noclipCam, false)
noclipCam = nil
DestroyCam(noClipCam, false)
noClipCam = nil
RenderScriptCams(false, false, 3000, true, false)
FreezeEntityPosition(ent, false)
SetEntityCollision(ent, true, true)
ResetEntityAlpha(ent)
SetPedCanRagdoll(cache.ped, true)
SetEntityVisible(ent, not invisible, false)
SetEntityVisible(ent, not Invisible)
ClearPedTasksImmediately(cache.ped)

if inVehicle then
FreezeEntityPosition(cache.ped, false)
SetEntityCollision(cache.ped, true, true)
ResetEntityAlpha(cache.ped)
SetEntityVisible(cache.ped, true, false)
SetEntityVisible(cache.ped, true)
SetPedIntoVehicle(cache.ped, ent, -1)
end
end)
Expand All @@ -212,49 +221,47 @@ end
function checkInputRotation()
CreateThread(function()
while inputRotEnabled do
while not noclipCam or IsPauseMenuActive() do Wait(0) end

while not noClipCam or IsPauseMenuActive() do Wait(0) end
local axisX = GetDisabledControlNormal(0, 1)
local axisY = GetDisabledControlNormal(0, 2)
local sensitivity = GetProfileSetting(14) * 2

if GetProfileSetting(15) == 0 then
if GetProfileSetting(15) == 0 --[[ Invert ]] then
sensitivity = -sensitivity
end

if math.abs(axisX) > 0 or math.abs(axisY) > 0 then
local rot = GetCamRot(noclipCam, 2)
local rotZ = rot.z + (axisX * sensitivity)
local yValue = axisY * sensitivity
local rotX = rot.x

if rotX + yValue > minY and rotX + yValue < maxY then
rotX = rot.x + yValue
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, rot.y, rotZ, 2)
SetCamRot(noClipCam, rotx, rotation.y, rotz, 2)
end

Wait(0)
end
end)
end

RegisterNetEvent('qbx_admin:client:noclip', function()
if GetInvokingResource() then return end -- Safety to make sure it is only called from the server
toggleNoClipMode()
end)

function toggleNoClipMode()
noclipEnabled = not noclipEnabled
inputRotEnabled = noclipEnabled

if noclipEnabled and inputRotEnabled then
function toggleNoClipMode(forceMode)
if forceMode ~= nil then
noClipEnabled = forceMode
inputRotEnabled = noClipEnabled
else
noClipEnabled = not noClipEnabled
inputRotEnabled = noClipEnabled
end
if noClipEnabled and inputRotEnabled then
toggleNoclip()
checkInputRotation()
end
end

RegisterNetEvent('qbx_admin:client:ToggleNoClip', function()
if GetInvokingResource() then return end
toggleNoClipMode()
end)

local showBlips = false
local showNames = false
local netCheck1 = false
Expand Down
Loading