Skip to content

RedM Adaptation - Flickering Issue #40

@levraimurphy

Description

@levraimurphy

Hi ! I'm currently working on a redm adaptation of this script, everything is working so far but sometimes i have those weirf flickering happening, do you guys experience it as well on fivem ?
https://streamable.com/tkv6ov

This is my part of the code where i drawsprite

local function CreateInteractions()
    for i = 1, nearbyAmount do
        local interaction = nearby[i]

        if interaction then
            local coords = interaction.coords or utils.getCoordsFromInteract(interaction)
            local isPrimary = i == 1

            if isPrimary and currentInteraction ~= interaction.id then
                currentInteraction = interaction.id
                currentAlpha = 255
                currentSelection = 1

            end

            if GetScreenCoordFromWorldCoord(coords.x, coords.y, coords.z) then

                local isClose = isPrimary and (interaction.curDist <= interaction.interactDst) and (not interaction.entity or interaction.ignoreLos or interaction.entity == CurrentTarget)
                if isPrimary and currentAlpha < 0 then
                    local options = interaction.options
                    local alpha = currentAlpha * -1

                    -- Citizen.InvokeNative(0xF5A2C681787E579D, 0.0, 0.0, 0.0, 0.0)
                    
                    SetDrawOrigin(coords.x, coords.y, coords.z)
                    SetScriptGfxDrawOrder(2 --[[ integer ]])
                    DrawSprite(settings.Style, interact, 0, 0, 0.0185, 0.03333333333333333, 0, 255, 255, 255, IsNightTime() and 200 or alpha)
                    SetScriptGfxDrawOrder(4)
                    -- Citizen.InvokeNative(0xE3A3DB414A373DAB)
                    Citizen.InvokeNative(0xE3A3DB414A373DAB)
                    local optionAmount = #options
                    local showDot = optionAmount > 1

                    for j = 1, optionAmount do
                        createOption(coords, options[j], j, interaction.width, showDot, alpha)
                    end

                    if currentSelection > optionAmount then
                        currentSelection = optionAmount
                    end

                    if currentSelection ~= 1 and (IsControlJustPressed(0, 0x6319DB71) or IsControlJustPressed(0, 0x62800C92)) then
                        currentSelection = currentSelection - 1
                    elseif currentSelection ~= optionAmount and (IsControlJustPressed(0, 0x05CA7C52) or IsControlJustPressed(0, 0x8BDE7443)) then
                        currentSelection = currentSelection + 1
                    end

                    if IsControlJustReleased(0, 0x41AC83D1) and isClose then
                        local option = options[currentSelection]

                        if option then
                            if option.action then
                                pcall(option.action, interaction.entity, interaction.coords, option.args, interaction.serverId)
                            elseif option.serverEvent then
                                TriggerServerEvent(option.serverEvent, option.args, interaction.serverId)
                            elseif option.event then
                                TriggerEvent(option.event, option, interaction.serverId)
                            end
                        end
                    end
                    ClearDrawOrigin()
                else

                    SetDrawOrigin(coords.x, coords.y, coords.z + 0.05)
                    SetScriptGfxDrawOrder(2 --[[ integer ]])
                    DrawSprite(settings.Style, pin, 0, 0, 0.010, 0.025, 0, 255, 255, 255, isPrimary and currentAlpha or 255)
                    SetScriptGfxDrawOrder(4)
                    Citizen.InvokeNative(0xE3A3DB414A373DAB)
                end

                ClearDrawOrigin()

                if isPrimary then
                    if isClose then
                        currentAlpha = math_max(-255, currentAlpha - 5)
                        if IsNightTime() then
                            currentAlpha = math_min(currentAlpha, 200) -- Limite l'opacité pour éviter le flickering
                        end
                    else
                        currentAlpha = math_min(255, currentAlpha + 5)
                    end
                end
            end
        end
    end
end
function IsNightTime()
    local hour = GetClockHours()
    return hour >= 20 or hour <= 5
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions