manups4e / ScaleformUI

ScaleformUI is a GTA menu styled API made with custom Scaleforms to be lighter, faster and visually better
Other
139 stars 49 forks source link

Did I mess up the code somewhere? #200

Closed GLiTcH2 closed 7 months ago

GLiTcH2 commented 7 months ago

So I have been working on my menu and slowly getting more familiar with all of this and love it, however when I recently was testing it in the game I noticed the healitem does not show the notification popup anymore, It was working fine and then suddenly just does not display the notification when clicked anymore. I tried to trace my steps back but really haven't changed anything in that part of the code in awhile so I don't know if I messed something up further down... Everything else seems to work just fine. Here is my code if it helps:

local ffire = false
local ccam = false

function CreateMenu()
    local txd = CreateRuntimeTxd("scaleformui")
    local duiBanner = CreateDui("https://i.imgur.com/LDWNH0j.png", 288, 160)
    CreateRuntimeTextureFromDuiHandle(txd, "menuBanner", GetDuiHandle(duiBanner))

    local playerMenu = UIMenu.New("G2 Menu", "Options", 20, 50, true, "scaleformui", "menubanner", true)
    playerMenu:MaxItemsOnScreen(7)
    playerMenu:AnimationEnabled(false)
    playerMenu:BuildingAnimation(MenuBuildingAnimation.NONE)
    playerMenu:ScrollingType(MenuScrollingType.CLASSIC)
    playerMenu:CounterColor(SColor.HUD_Yellow)
    playerMenu:MouseSettings(false, false, true, false, true)

    local healitem = UIMenuItem.New("Heal Player", "Click this to heal yourself!")
    playerMenu:AddItem(healitem)
    healitem:LeftBadge(BadgeStyle.STAR)

    playerMenu.OnItemSelect = function(menu, item, index)
        if (item == healitem) then
            ScaleformUI.Notifications:ShowNotification("Function not yet active!")
        end
    end

    local friendlyfireitem = UIMenuCheckboxItem.New("🔫 Enable/Disable Friendly Fire", ffire, 0, "Turns Friendly Fire On or Off for yourself")
    playerMenu:AddItem(friendlyfireitem)

    friendlyfireitem.OnCheckboxChanged = function(menu, item, checked)
        ffire = checked
        if checked then
            ScaleformUI.Notifications:ShowNotification("Friendly Fire has been turned on!")
            Citizen.CreateThread(function()
                while true do
                    Citizen.Wait(0)
                    SetCanAttackFriendly(GetPlayerPed(-1), true, true)
                    NetworkSetFriendlyFireOption(true)
                end
            end)
        else
            ScaleformUI.Notifications:ShowNotification("Friendly Fire has been turned off!")
            Citizen.CreateThread(function()
                while true do
                    Citizen.Wait(0)
                    SetCanAttackFriendly(GetPlayerPed(-1), false, false)
                    NetworkSetFriendlyFireOption(false)
                end
            end)
        end
    end

    local cameraitem = UIMenuCheckboxItem.New("🎥 Disable Cinematic Cameras", ccam, 0, "Turns all Cineamtic Cameras Off")
    playerMenu:AddItem(cameraitem)

    cameraitem.OnCheckboxChanged = function(menu, item, checked)
        ccam = checked
        if checked then
            ScaleformUI.Notifications:ShowNotification("All Cinematic Cameras have been turned off!")
            Citizen.CreateThread(function()
                while true do
                    InvalidateIdleCam()
                    InvalidateVehicleIdleCam()
                    Wait(1000)
                end
            end)
            Citizen.CreateThread(function()
                while true do
                    Citizen.Wait(0)
                    SetCinematicModeActive(false)
                end
            end)
        end    
    end

 local trainitem = UIMenuItem.New("🚂 Enable Ambient Trains", "Click this to spawn ambient trains in the world")
 playerMenu:AddItem(trainitem)

 playerMenu.OnItemSelect = function(menu, item, index)
    if (item == trainitem) then
        ScaleformUI.Notifications:ShowNotification("Trains will now spawn in the world!")
        Citizen.CreateThread(function()
            while true do
                Citizen.Wait(0)
                SwitchTrainTrack(0, true) -- Setting the Main train track(s) around LS and towards Sandy Shores active
                SwitchTrainTrack(3, true) -- Setting the Metro tracks active
                SetTrainTrackSpawnFrequency(0, 120000) -- The Train spawn frequency set for the game engine
                SetTrainTrackSpawnFrequency(3, 120000) -- The Metro spawn frequency set for the game engine
                SetRandomTrains(true) -- Telling the game we want to use randomly spawned trains
            end
        end)
    end
 end

    local aimassistitem = UIMenuListItem.New("🎯 Targetting Mode", { "Assisted Aim - Full", "Assisted Aim - Partial", "Free Aim - Assisted", "Free Aim" }, 1, "Choose your preferred Targeting Mode (This option does not function yet)")
    playerMenu:AddItem(aimassistitem)

    playerMenu:Visible(true)

end
Citizen.CreateThread(function()
    while true do
        Wait(0)
        if IsControlPressed(0, 206) and IsControlJustPressed(0, 193) and not MenuHandler:IsAnyMenuOpen() then
            CreateMenu()
        end
    end
end)
manups4e commented 7 months ago

try to shift playerMenu:AddItem(healitem) under the Activated event, like this:

    local healitem = UIMenuItem.New("Heal Player", "Click this to heal yourself!")
    healitem:LeftBadge(BadgeStyle.STAR)

    playerMenu.OnItemSelect = function(menu, item, index)
        if (item == healitem) then
            ScaleformUI.Notifications:ShowNotification("Function not yet active!")
        end
    end
    playerMenu:AddItem(healitem)
manups4e commented 7 months ago

since you don't have a lot of items in your menu.. try using the item.Activated event itself..


healitem.Activated = function(menu, item)
    ScaleformUI.Notifications:ShowNotification("Function not yet active!")
end
GLiTcH2 commented 7 months ago

try to shift playerMenu:AddItem(healitem) under the Activated event, like this:

    local healitem = UIMenuItem.New("Heal Player", "Click this to heal yourself!")
    healitem:LeftBadge(BadgeStyle.STAR)

  playerMenu.OnItemSelect = function(menu, item, index)
        if (item == healitem) then
            ScaleformUI.Notifications:ShowNotification("Function not yet active!")
        end
    end
    playerMenu:AddItem(healitem)

Is this the proper way to go about my code, Should I be doing this for all the other items in my menu?

since you don't have a lot of items in your menu.. try using the item.Activated event itself..

healitem.Activated = function(menu, item)
    ScaleformUI.Notifications:ShowNotification("Function not yet active!")
end

Thank you this method got it working again.

manups4e commented 7 months ago

playerMenu.OnItemSelect should be working buti suggest to use it when you have 10 items or more.. where you need everything in one place

GLiTcH2 commented 7 months ago

Ah ok, Thank you for the help!