NicooPasPris / nicoo_charcreator

Fivem Character Creator
47 stars 24 forks source link

To make the scale work for Face Features... #20

Open Twiitchter opened 3 years ago

Twiitchter commented 3 years ago

Add this the the skinchanger AND the menu.lua.

function round(number, decimals)
    local power = 10^decimals
    return math.floor(number * power) / power
end

function CorrectFloat(num)
    local xNum = 0.0
        xNum = (num-0.50)*2    
    return round(xNum, 2)
end

I didn't bother adding any checks to ensure tis going to be a number on the input. just don't put strings in it please.

Will turn 0.50 from the square to 0.0. Every 0.01 in addition is basically then 0.02... quick maths.

Find this in the menu.lua

                if PanelVisage.Square.enable then
                    RageUI.GridPanel(PanelVisage.Square.x, PanelVisage.Square.y, PanelVisage.Square.Top, PanelVisage.Square.Bottom, PanelVisage.Square.Left, PanelVisage.Square.Right, function(Hovered, Active, X, Y)
                        if PanelVisage.Square.lastItem == PanelVisage.Square.currentItem then
                            PanelVisage.Square.x = X
                            PanelVisage.Square.y = Y
                        else
                            PanelVisage.Square.x = PanelVisage.Square[PanelVisage.Square.currentItem].x
                            PanelVisage.Square.y = PanelVisage.Square[PanelVisage.Square.currentItem].y
                        end
                        if Active then
                            PanelVisage.Square[PanelVisage.Square.currentItem].x = X
                            PanelVisage.Square[PanelVisage.Square.currentItem].y = Y   

                            local x = PanelVisage.Square[PanelVisage.Square.currentItem].x
                            local y = PanelVisage.Square[PanelVisage.Square.currentItem].y                 

                            SetPedFaceFeature(GetPlayerPed(-1), PanelVisage.Square.IndexX, x)
                            SetPedFaceFeature(GetPlayerPed(-1), PanelVisage.Square.IndexY, y)
                            Visage[PanelVisage.Square.IndexX] = x
                            Visage[PanelVisage.Square.IndexY] = y
                        end

                    end)
                end

Make it this.

                if PanelVisage.Square.enable then
                    RageUI.GridPanel(PanelVisage.Square.x, PanelVisage.Square.y, PanelVisage.Square.Top, PanelVisage.Square.Bottom, PanelVisage.Square.Left, PanelVisage.Square.Right, function(Hovered, Active, X, Y)
                        if PanelVisage.Square.lastItem == PanelVisage.Square.currentItem then
                            PanelVisage.Square.x = X
                            PanelVisage.Square.y = Y
                        else
                            PanelVisage.Square.x = PanelVisage.Square[PanelVisage.Square.currentItem].x
                            PanelVisage.Square.y = PanelVisage.Square[PanelVisage.Square.currentItem].y
                        end
                        if Active then
                            PanelVisage.Square[PanelVisage.Square.currentItem].x = X
                            PanelVisage.Square[PanelVisage.Square.currentItem].y = Y   

                            local x = PanelVisage.Square[PanelVisage.Square.currentItem].x
                            local y = PanelVisage.Square[PanelVisage.Square.currentItem].y                 
                            local xa = CorrectFloat(x)
                            local ya = CorrectFloat(y)
                            SetPedFaceFeature(GetPlayerPed(-1), PanelVisage.Square.IndexX, xa)
                            SetPedFaceFeature(GetPlayerPed(-1), PanelVisage.Square.IndexY, ya)
                            Visage[PanelVisage.Square.IndexX] = x
                            Visage[PanelVisage.Square.IndexY] = y
                        end

                    end)
                end

Find this in the skinchanger

    elseif type == 'facefeature' then
        Character[Face[index]] = v
    end
end)

Make it this.

    elseif type == 'facefeature' then
        Character[Face[index]] = CorrectFloat(v)
    end
end)
Twiitchter commented 3 years ago

Probably should have done a math.floor in there somewhere to prevent long winded lua decimals.

Amended OP with simple decimal rounding as found all over stackoverflow.