• Creating a vgui element based on lua files.
    1 replies, posted
I'm trying to figure out a way to create a vgui element(or so called achievement) with each lua file. Each lua file for the achievement's, will have there own function on how to achieve it, but the problem im having is trying to understand how to create a new vgui element for each lua file that is found. If you know of any links and or any tutorials based on anything like this, I would greatly appreciate it.
Load each lua file, in which you register a new vgui element to a master table, which in then is used by your menu to automatically index each achievement in the table(set the key as the achievement name) creates a new button which activates the new element. For adding achievement files do like [lua] local ach = {} ach.Name = 'This' ach.CheckFunc = function(ply) end ach.Menu = function(parent, w, h) //do stuff end achievement.Register(ach) [/lua] and for registering, autoload the files and do [lua] local menus = {} function achievement.Register(tblData) menus[ tblData.Name ] = tblData.Menu end [/lua] and finally for populating your menu with the elements [lua] local active = nil for k,v in pairs(menus) do local a = vgui.Create("DButton", parent) a:SetText( k ) function a:DoClick() if (active) then active:Close() active = nil end active = menus[ k ](parent, parent:GetWide(), parent:GetTall()) or nil end end [/lua] This is the general idea, make sure to add checks for clientside and serverside when registering, and optimally you should load all these shared, so you don't have to send a massive menu table to the client. But you should get the idea here.
Sorry, you need to Log In to post a reply to this thread.