What is the correct way of including (Server & Client) lua files?
I have it working, but it just seems kinda 50/50 if everything loads okay.
For example, I have a shared function:
[code]
function LoadPlugins()
plugins = plugins or {}
local plugins = file.Find( GAMEMODE_FOLDER .. "/gamemode/admin/plugins/*.lua", "LUA" )
for _, plugin in pairs( plugins ) do
local prefix = string.Left( plugin, string.find( plugin, "_" ) - 1 )
evolve.pluginFile = plugin
if ( CLIENT and ( prefix == "sh" or prefix == "cl" ) ) then
include( "plugins/" .. plugin )
elseif ( SERVER ) then
include( "plugins/" .. plugin )
if ( prefix == "sh" or prefix == "cl" ) then MsgN("Added: " .. plugin ); AddCSLuaFile ( "plugins/" .. plugin ) end
end
end
end
[/code]
This works, sometimes. I call "LoadPlugins()" soon as the server starts, then when the client is loading.
The server-side works fine, AddCSLuaFile() calls fine. However the client complains about not having the file. What the fuck?
If i remove that code from a function and run it directly (outside a function) everything is working. Why?
The twist, is that on the client, it sees the files. (file.Find() returns all the server sent files) - it just errors out on the include() line saying it wasn't found.
But find.Files() finds it!
[b]EDIT[/b]
Also, I noticed. If I change the client-side include line, to the direct path it works. I thought include() is relative to the current file?
Frustrated.
[QUOTE=Drak_Thing;40848674]What is the correct way of including (Server & Client) lua files?
I have it working, but it just seems kinda 50/50 if everything loads okay.
For example, I have a shared function:
[code]
function LoadPlugins()
plugins = plugins or {}
local plugins = file.Find( GAMEMODE_FOLDER .. "/gamemode/admin/plugins/*.lua", "LUA" )
for _, plugin in pairs( plugins ) do
local prefix = string.Left( plugin, string.find( plugin, "_" ) - 1 )
evolve.pluginFile = plugin
if ( CLIENT and ( prefix == "sh" or prefix == "cl" ) ) then
include( "plugins/" .. plugin )
elseif ( SERVER ) then
include( "plugins/" .. plugin )
if ( prefix == "sh" or prefix == "cl" ) then MsgN("Added: " .. plugin ); AddCSLuaFile ( "plugins/" .. plugin ) end
end
end
end
[/code]
This works, sometimes. I call "LoadPlugins()" soon as the server starts, then when the client is loading.
The server-side works fine, AddCSLuaFile() calls fine. However the client complains about not having the file. What the fuck?
If i remove that code from a function and run it directly (outside a function) everything is working. Why?
The twist, is that on the client, it sees the files. (file.Find() returns all the server sent files) - it just errors out on the include() line saying it wasn't found.
But find.Files() finds it!
[b]EDIT[/b]
Also, I noticed. If I change the client-side include line, to the direct path it works. I thought include() is relative to the current file?
Frustrated.[/QUOTE]
try this: (untested)
[lua]
function LoadPlugins()
plugins = plugins or {}
local root = "gamemodes/"..GAMEMODE_FOLDER
local trimIndex = string.len(root)
local plugins = file.Find( root.."/gamemode/admin/plugins/*.lua", "MOD" )
for _, plugin in pairs( plugins ) do
local prefix = string.Left( plugin, string.find( plugin, "_" ) - 1 )
evolve.pluginFile = plugin
if ( CLIENT and ( prefix == "sh" or prefix == "cl" ) ) then
include( "admin/plugins/" .. plugin )
elseif ( SERVER ) then
include( "admin/plugins/" .. plugin )
if ( prefix == "sh" or prefix == "cl" ) then MsgN("Added: " .. plugin ); AddCSLuaFile ( "admin/plugins/" .. plugin ) end
end
end
end
[/lua]
No, that doesn't work. Again, if I do: include( "direct-path-to-lua-file-here" ) works, but I thought it's relative to path from the file that it's being called from.
This is what I'm using:
init.lua
[lua]
for k, v in pairs(file.Find("blockwars/gamemode/vgui/*.lua", "LUA")) do
AddCSLuaFile( "vgui/" .. v )
end
for k, v in pairs(file.Find("blockwars/gamemode/cl_*.lua", "LUA")) do
AddCSLuaFile( v )
end
for k, v in pairs(file.Find("blockwars/gamemode/sh_*.lua", "LUA")) do
AddCSLuaFile( v )
end
for k, v in pairs(file.Find("blockwars/gamemode/sh_*.lua", "LUA")) do
include( v )
end
for k, v in pairs(file.Find("blockwars/gamemode/sv_*.lua", "LUA")) do
include( v )
end[/lua]
cl_init.lua
[lua]for k, v in pairs(file.Find("blockwars/gamemode/vgui/*.lua", "LUA")) do
include( "vgui/" .. v )
end
for k, v in pairs(file.Find("blockwars/gamemode/cl_*.lua", "LUA")) do
if v != "cl_init.lua" then include( v ) end
end
for k, v in pairs(file.Find("blockwars/gamemode/sh_*.lua", "LUA")) do
include( v )
end[/lua]
Hope it helps.
Sorry, you need to Log In to post a reply to this thread.