Skip to content
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

Menu freeze when they are too much buttons in a menu #39

Open
spacevx opened this issue Jun 19, 2021 · 7 comments
Open

Menu freeze when they are too much buttons in a menu #39

spacevx opened this issue Jun 19, 2021 · 7 comments

Comments

@spacevx
Copy link

spacevx commented Jun 19, 2021

Hello, when there are too much buttons in a menu, sometimes, for some reasons, the menu freeze itself and we need to restart the script in order to unfreeze the controls on the menu. In my case, it happens on the players list.

local function setupMenu(group)
    local menu = MenuV:CreateMenu(Config.translations["menuTitle"], Config.translations["menuSubtitle"], 'topleft', 255, 0, 0, 'size-125', 'default', 'menuv', 's1n_adminmenu_main', 'native')
	local target

	for _, subMenuType in ipairs(Sections) do
        if subMenuType.disable then goto continue end

		local subMenu = MenuV:CreateMenu(subMenuType.name, "", "topleft", 255, 0, 0, 'size-125', 'default', 'menuv', 'stl_adminmenu_' .. subMenuType.name, 'native')

		menu:AddButton({ label = subMenuType.name, value = subMenu })

		if subMenuType.name == Config.translations["sectionManagePlayers"] then
			local targetMenu = MenuV:CreateMenu(Config.translations["menuActionsTitle"], Config.translations["menuActionsSubtitle"], "topleft", 255, 0, 0, 'size-125', 'default', 'menuv', 's1n_adminmenu_target', 'native')

			for _, action in ipairs(subMenuType.functions) do
				if not isNotBlacklist(action.blacklistID, group) and not action.disable then
					if action.type == "checkbox" then
						targetMenu:AddCheckbox({ label = action.name, value = "n", change = function(item)
							ESX.TriggerServerCallback("s1n_adminmenu:logDiscord", function()
								action.trigger(PlayerPedId(), target, item.Value)
							end, action.name, target, item.Value)
						end })
					elseif action.type == "slider" then
						targetMenu:AddSlider({ label = action.name, values = action.values, select = function(_, value)
							ESX.TriggerServerCallback("s1n_adminmenu:logDiscord", function()
								action.trigger(PlayerPedId(), target, value)
							end, action.name, target, value)
						end })
					else
						targetMenu:AddButton({ label = action.name, select = function() 
							ESX.TriggerServerCallback("s1n_adminmenu:logDiscord", function()
								action.trigger(PlayerPedId(), target)
							end, action.name, target)
						end })	
					end
				end
			end
			
			subMenu:On("open", function (menu)
				ESX.TriggerServerCallback("s1n_adminmenu:getAllPlayers", function(players)
					menu:ClearItems()
					
					for k, player in pairs(players) do
						menu:AddButton({ label = ('%s [ID: %s]'):format(player.name, k), value = targetMenu, select = function()
							target = player
						end })
					end
				end)
			end)
		else
			for _, action in ipairs(subMenuType.functions) do
				if not isNotBlacklist(action.blacklistID, group) and not action.disable then
					if action.type == "checkbox" then
						subMenu:AddCheckbox({ label = action.name, value = "n", change = function(item)
							ESX.TriggerServerCallback("s1n_adminmenu:logDiscord", function()
								action.trigger(PlayerPedId(), item.Value, PlayerId())
							end, action.name, false, item.Value)
						end })
					elseif action.type == "slider" then
						subMenu:AddSlider({ label = action.name, values = action.values, select = function(_, value)
							ESX.TriggerServerCallback("s1n_adminmenu:logDiscord", function()
								action.trigger(PlayerPedId(), value, PlayerId())
							end, action.name, false, value)
						end })
					else
						subMenu:AddButton({ label = action.name, select = function() 
							ESX.TriggerServerCallback("s1n_adminmenu:logDiscord", function()
								action.trigger(PlayerPedId(), PlayerId())
							end, action.name)
						end })	
					end
				end
			end
		end

        ::continue::
	end

	menu:OpenWith('keyboard', Config.keyOpenMenu)
end
@spacevx spacevx changed the title Menu freeze when they are too much button in a menu Menu freeze when they are too much buttons in a menu Jun 23, 2021
@GhostDaGhost
Copy link

https://i.imgur.com/iKVmysk.png

Can confirm this is still happening. I have a lot of items in some of my menus. I can't give an exact count but if needed, I can provide it. Is there any hope of this being fixed?

@Artzalez
Copy link

me too, same problem here with 312 buttons

@Artzalez
Copy link

image

@Artzalez
Copy link

I fixed it with a Citizen.Wait(5) on the foreach

@Aero-Codes
Copy link

I fixed it with a Citizen.Wait(5) on the foreach

what you mean foreach? in JS?

@spacevx
Copy link
Author

spacevx commented Jul 31, 2021

I fixed it with a Citizen.Wait(5) on the foreach

what you mean foreach? in JS?

Yeah surely

@Aero-Codes
Copy link

I fixed it with a Citizen.Wait(5) on the foreach

what you mean foreach? in JS?

Yeah surely

JS is compiled i don't think its JS, and also I tried to put Wait(5) in foreach in lua it helps a bit but still lagging

@spacevx spacevx closed this as completed Sep 5, 2021
@spacevx spacevx reopened this Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants