-
-
Notifications
You must be signed in to change notification settings - Fork 428
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
Add new function isPlayerCrosshairVisible #3720
Add new function isPlayerCrosshairVisible #3720
Conversation
The below script (from me) is 100% accurate to stop "zero recoil GTA bug", by blocking fire without aiming. I've not spotted task states inconsistency with well-implemented scripts. --- Put weapons here, set to true if you want hipfire blocked for it
-- @warning don't use 0 or 36 as they are already blocked
local antiHipfireWeapons = {
[22] = true,
[23] = true,
[24] = true,
[25] = true,
[26] = true,
[27] = true,
[28] = true,
[29] = true,
[30] = true,
[31] = true,
[32] = true,
[33] = true,
[38] = true,
}
-- So we can't lose track of our state if some other script decides to use toggleControl
-- or when this script gets stopped we need to reset the state
-- this is set true when we're using it, false when we're not
local fireControlLock = false
-- Time since last antiHipfire check
local lastTick = 0
-- Time interval between each hipfire check
local checkInterval = 300
--- Disable hipfire for certain weapons
local function antiHipfire()
local curTick = getTickCount()
if curTick - lastTick > checkInterval then
if getPedOccupiedVehicle(localPlayer) then
return
end
local wp = getPedWeapon(localPlayer)
-- Stop here if it's not anti hipfire weapon
if not antiHipfireWeapons[wp] and fireControlLock then
toggleControl("fire", true)
fireControlLock = false
return
end
local aiming = getPedControlState(localPlayer, "aim_weapon")
if antiHipfireWeapons[wp] and isControlEnabled("fire") ~= aiming then
toggleControl("fire", aiming)
fireControlLock = not aiming
end
lastTick = curTick
end
end
addEventHandler("onClientPreRender", root, antiHipfire)
-- If we stop this resource make sure we undo toggleControl
addEventHandler("onClientResourceStop", resourceRoot, function ()
if fireControlLock then
toggleControl("fire", true)
end
end) |
The problem is that ControlState "aim_weapon" and task "TASK_SIMPLE_USE_GUN" returns true at the start of aiming when the aiming animation just started, so even with this code its possible to shoot without a fully visible crosshair. If you use a sawed, your first shoot won't have problem, but the second shoot will have no-recoil and it will be shot at head level. (if you have low fps settings, you can make this with the first shoot too) But. Your code still fixes a problem: If you press TAB it opens the scoreboard. Hold TAB, then press right click, you will now shoot, because TAB also fires the gun. You'll have a cursor as well, because scoreboard has settings. If you move the cursor to the center of the scoreboard and stop holding the TAB, the crosshair and scoreboard will disappear but you will be able to shoot if you press left click, or ctrl, without crosshair, so without recoil. |
I see. This will be nice to have in the next main rolling update.. |
This PR adds the function
isPlayerCrosshairVisible
, which allows checking if the crosshair is actually visible on the screen. Sometimes, checking if a player is aiming based on tasks can be inaccurate, as simply holding the mouse button for a second can falsely indicate that the player is aiming. This function was created to address the issue reported here, and I believe it can also help in detecting aimbots more easily. For instance, if a player is hitting headshots without even seeing the crosshair, it's a clear sign that something might be wrong with him.If the crosshair is hidden using
setPlayerHudComponentVisible
, the function returns false.I have one question though: The function currently returns true for weapons like the
spraycan
andfire extinguisher
. In reality, the crosshair is intentionally hidden for these weapons in GTA’s code. Should i leave it as it is, or should i add a special condition to always return false for these two weapons?Fixes #3711