inferno-collection / Weapons

Adds fire modes to the weapons of your choice, as well as more realistic reloads, and more.
Other
12 stars 9 forks source link

[Bug] Flashlight Issues #8

Closed Mart475 closed 4 years ago

Mart475 commented 4 years ago

The flashlight has multiple issues, and these center around turning it on/off.

When you spam the E button to turn it on/off, it sometimes gets stuck and doesn't want to turn on/off. This was fixed by adding a delay in this loop below.

-- Toggle Weapon Flashlight Loop Citizen.CreateThread(function() while true do Citizen.Wait(0)

    -- If player has a weapon
    if FireMode.LastWeapon then
        local PlayerPed = PlayerPedId()
        local RemovedFlashlight = true

        -- Loop though all flashlights
        for Flashlight, _ in pairs(Flashlights.Hashes) do
            -- If weapon has flashlight
            if HasPedGotWeaponComponent(PlayerPed, FireMode.LastWeapon, GetHashKey(Flashlight)) then
                if not FireMode.WeaponFlashlights[FireMode.LastWeapon] then
                    FireMode.WeaponFlashlights[FireMode.LastWeapon] = {Flashlight, false }
                elseif FireMode.WeaponFlashlights[FireMode.LastWeapon][2] then
                    TriggerServerEvent('Weapons:Server:Toggle',
                        FireMode.WeaponFlashlights[FireMode.LastWeapon][2],
                        FireMode.WeaponFlashlights[FireMode.LastWeapon][1],
                        FireMode.LastWeapon
                    )
                end

                RemovedFlashlight = false
                break
            end
        end

        if RemovedFlashlight then
            FireMode.WeaponFlashlights[FireMode.LastWeapon] = nil
            TriggerServerEvent('Weapons:Server:Toggle', false)
        end

        -- If E just pressed
        if IsDisabledControlJustPressed(0, 54) then
            if FireMode.WeaponFlashlights[FireMode.LastWeapon] then
                -- Toggle flashlight
                FireMode.WeaponFlashlights[FireMode.LastWeapon][2] = not FireMode.WeaponFlashlights[FireMode.LastWeapon][2]
                TriggerServerEvent('Weapons:Server:Toggle',
                    FireMode.WeaponFlashlights[FireMode.LastWeapon][2],
                    FireMode.WeaponFlashlights[FireMode.LastWeapon][1],
                    FireMode.LastWeapon
                )
                PlaySoundFrontend(-1, 'COMPUTERS_MOUSE_CLICK', 0, 1)
                Citizen.Wait(100)
            end
        end
    end
end

end)

Citizen.Wait(100) under PlaySoundFrontend.

It could be increased and it actually stops it from happening.

Another small issue with the script is sometimes the default vanilla flashlight goes on, as the script's master loop loops every 1ms and if you time it perfectly, it can get stuck on and you can't turn it off except switiching weapons.

Was in a call with the creator and we managed to fix one of the issues, but he said that the vanilla flashlight turning on/off is probably just the disable bit being in the master loop, and it needs to be somewhere else. Please fix. Thanks :)

cm8263 commented 4 years ago

Attempted to resolve in https://github.com/inferno-collection/Weapons/commit/782f5a37c4b28685d9dc4538b59c5bf9d3330582.

PERPGamer commented 4 years ago

I have build 782f5a3 on my server and it seems that some players are unable to turn on the flashlight. It clicks but they do not see it. Update: I TPed to the player, turned on my light, and now he can see it. It seems whenever I turn on my light his updates (aka he can turn it on or off) but if I don't turn it on or off, he can't toggle it Update 2: Removed: if not LastCount then LastCount = #Flashlights end

if #Flashlights ~= LastCount then LastCount = #Flashlights end and kept TriggerClientEvent('Weapons:Client:Return', -1, Flashlights) fixes the issue

cm8263 commented 4 years ago

Thanks for the feedback, that was an experiment to see if we could reduce the spam sent to the client, clearly it's not working lol.

Thanks, I'll change it

cm8263 commented 4 years ago

Attempted to resolve in https://github.com/inferno-collection/Weapons/commit/e6479b626409e64852ce61c9a1e967e62276e5b7.

cm8263 commented 4 years ago

Resolved in Public Beta Version 1.3.

https://github.com/inferno-collection/Weapons/releases/tag/v1.3-beta