• Plugin style client LUA loading.
    2 replies, posted
I want to load client LUA files like plugins, My issue is I cant find a way of doing this and get it to work. This is what I've got currently: [lua]print( "Launching plugins." ) local files, folders = file.Find( "lam/plugins/*", "LUA" ) for k, v in pairs ( folders ) do if SERVER then include( "plugins/"..v.."/init.lua" ) print( "Launched \""..v.."\"" ) else include( "plugins/"..v.."/cl_init.lua" ) print( "Launched \""..v.."\"" ) end end[/lua] The server reads the files fine but the clients don't have the files / folders from the server. Each plugins init.lua contains AddCSLuaFile( "cl_init.lua" ) and it still refuses to show up in the file.Find return. Can anyone point me in the correct direction or give me an alternative?
You need to send them to the client. [code]AddCSLuaFile( "plugins/" .. v .. "/cl_init.lua" )[/code]
Wrote this just for you. It includes .lua files that start with "sv_", sends that start with "cl_", and includes + sends that start with "sh_". As well as go through all subfolders. (So don't make any directory junctions else you'll get caught in an infinite paradox of buttrape.) [lua] -- The folder relative to "garrysmod/garrysmod/lua/". local s_BaseFolder = "myfolder"; local function ParsePlugins( s_Base ) local t_Files, t_Folders = file.Find( "lua/" .. s_Base .. "/*", "GAME" ); -- Make sure the table exists before we iterate through it. if ( t_Files ~= nil ) then -- Iterate through the table of files. for k, v in pairs( t_Files ) do -- Ensure this file is a .lua file. if ( string.EndsWith( v, ".lua" ) ) then -- Check file prefixes and handle accordingly. if ( string.StartWith( v, "sh_" ) ) then -- Both include serverside, and send to the client. include( s_Base .. "/" .. v ); AddCSLuaFile( s_Base .. "/" .. v ); elseif ( string.StartWith( v, "sv_" ) ) then -- Load on the server. include( s_Base .. "/" .. v ); elseif ( string.StartWith( v, "cl_" ) ) then -- Send to the client. AddCSLuaFile( s_Base .. "/" .. v ); end end end end -- Same thing here as before, make sure the table is valid. if ( t_Folders ~= nil ) then -- Iterate through the table of folders. for k, v in pairs( t_Folders ) do -- Search for plugins in this subfolder. ParsePlugins( s_Base .. "/" .. v ); end end end ParsePlugins( s_BaseFolder );[/lua]
Sorry, you need to Log In to post a reply to this thread.