• Config file for derma
    5 replies, posted
Hi, So I'm doing a derma panel with mixed features for VIPs, and I wish to make it as and addons, so its easy to move around on my servers. What I'm struggling with, is that I have a cl_init file, loacated in [QUOTE]addons/vip_perks/lua/autorun/client/cl_init.lua[/QUOTE] What I wish to do, is to make it easy to config by having a config file. I've seen coders using ..Example.change.. and then in their config file, they had something look-a-like [QUOTE]Example.change = "Hey"[/QUOTE] I hope you understand what I'm trying to say.. But where would I place this config file, and what to include? --Thanks
The way this kind of system works is by having [B]global[/B] variables. You would perhaps make a config file like so; [lua] mymodconfig={} mymodconfig.Name="Test" [/lua] Then in your cl_init code you would refernce it like so [lua] local DermaPanel = vgui.Create( "DFrame" ) -- Creates the frame itself DermaPanel:SetPos( 50,50 ) -- Position on the players screen DermaPanel:SetSize( 1000, 900 ) -- Size of the frame DermaPanel:SetTitle( mymodconfig.Name ) -- Title of the frame DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) -- Draggable by mouse? DermaPanel:ShowCloseButton( true ) -- Show the close button? DermaPanel:MakePopup() -- Show the frame [/lua] Becareful when using global tables and variables, since they can be modifed/accessed by all the files ran. So don't use a generic name like "config".
[QUOTE=Alig96;43592313]The way this kind of system works is by having [B]global[/B] variables. You would perhaps make a config file like so; [lua] mymodconfig={} mymodconfig.Name="Test" [/lua] Then in your cl_init code you would refernce it like so [lua] local DermaPanel = vgui.Create( "DFrame" ) -- Creates the frame itself DermaPanel:SetPos( 50,50 ) -- Position on the players screen DermaPanel:SetSize( 1000, 900 ) -- Size of the frame DermaPanel:SetTitle( mymodconfig.Name ) -- Title of the frame DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) -- Draggable by mouse? DermaPanel:ShowCloseButton( true ) -- Show the close button? DermaPanel:MakePopup() -- Show the frame [/lua] Becareful when using global tables and variables, since they can be modifed/accessed by all the files ran. So don't use a generic name like "config".[/QUOTE] You're my saviour. However, how do I make it find the config file in cl_init? And where to place the config file? Thanks:rolleyes:
[QUOTE=The Beta;43592411]snip[/QUOTE] Probably not the most efficient way, maybe a "pro" lua coder can advise better, but here's my method. Make a new file called sh_config.lua in addons/vip_perks/lua/autorun/ Then have it setup like so: [lua] //Shared Config sh_mymodconfig={} --------------- //Server Config if SERVER then sv_mymodconfig={} end //Client Config if CLIENT then cl_mymodconfig={} end [/lua] You will then have your global tables set up and can then set them by referencing them.
[QUOTE=Alig96;43592477]Probably not the most efficient way, maybe a "pro" lua coder can advise better, but here's my method. Make a new file called sh_config.lua in addons/vip_perks/lua/autorun/ Then have it setup like so: [lua] //Shared Config sh_mymodconfig={} --------------- //Server Config if SERVER then sv_mymodconfig={} end //Client Config if CLIENT then cl_mymodconfig={} end [/lua] You will then have your global tables set up and can then set them by referencing them.[/QUOTE] Thanks, but do I need include the config file in cl_init.lua? And how is that done, I know something about include("") and AddCS If you want to, can you add me on steam for an instance?:smile:
If you put it in the folder I said, it should be automatically run at server start/map change on both client and server, If I remember. If want to manually include it, then in your init script put: AddCSLuaFile("sh_config.lua") include( "sh_config.lua" ) In your cl_init.lua include( "sh_config.lua" ) They are relative to where they were called. Feel free to add me.
Sorry, you need to Log In to post a reply to this thread.