• AddCSLuaFile() && Include() issues
    4 replies, posted
Hi, first of all let me give you guys the block of code I am having trouble with: (forums fucked up my indexing, I'm sorry.) [code]//Auto-Load our Plugins. INCLUDE = function(SOURCE) for k, v in pairs(file.Find("gamemodes/skeleton/gamemode/"..SOURCE.."/*.lua", "GAME")) do local filter = string.sub(v, 1, 2); print("SOURCE FILE- "..SOURCE.." LOADING- "..v); if filter != "cl" or filter == "sh" then include(SOURCE.."/"..v); end if filter == "cl" or filter == "sh" then AddCSLuaFile(SOURCE.."/"..v); end end end INCLUDE("Plugins");[/code] This is being called server-side, I've already tried it in shared but it becomes a cluster. Can anyone share with me a good method of Include() and AddCSLuaFile() plugins? I'm trying to get this to work so that I don't need to manually add plugins to my gamemode. I am also having troubles with the fact that if I don't have a cl_init in my plugin folder it spews an error that it cannot find Plugins/cl_init.lua when cl_init.lua already exists..
What makes it not work when called shared? ( this is the only way btw ) As for your cl_init.lua, make sure it's not empty and that it doesn't contain errors.
I didn't want to go this way but it seemed like the most concrete way to do it: [lua] for k, v in pairs(file.Find("skeleton/gamemode/Plugins/*.lua", "LUA")) do local FILTER = string.sub(v, 1, 3); print("-----"); if FILTER == "sh_" then include("Plugins/"..v); if SERVER then AddCSLuaFile("Plugins/"..v); end print("SHARED FILE - "..v); end end if SERVER then for k, v in pairs(file.Find("skeleton/gamemode/Plugins/*.lua", "LUA")) do local FILTER = string.sub(v, 1, 3); print("-----"); if FILTER == "sv_" then include("Plugins/"..v); print("SERVER FILE - "..v); elseif FILTER == "cl_" then AddCSLuaFile("Plugins/"..v); print("ADDED CLIENT FILE - "..v); end end end if CLIENT then for k, v in pairs(file.Find("skeleton/gamemode/Plugins/*.lua", "LUA")) do local FILTER = string.sub(v, 1, 3); print("-----"); if FILTER == "cl_" then include("Plugins/"..v); print("CLIENT FILE - "..v); end end end [/lua] Since I wasn't checking the SERVER and CLIENT correctly it was including cl_ folders sometimes on the server and still searching for cl_init which broke the whole script.
Can't you do simple logic? if prefix=="sh" or ( CLIENT and prefix == "cl" ) or ( SERVER and prefix == "sv" ) then include (file) elseif ( SERVER and prefix == "cl" or prefix=="sh" ) then addcsluafile (file) end
I've been up all night, I'll re-write soon. Sorry [editline]24th November 2013[/editline] [lua] for k, v in pairs(file.Find("skeleton/gamemode/"..SOURCE.."/*.lua", "LUA")) do local FILTER = string.sub(v, 1, 3); print("-----"); if SERVER then if FILTER == "sv_" or FILTER == "sh_" then include(SOURCE.."/"..v); if FILTER == "sh_" then AddCSLuaFile(SOURCE.."/"..v); print("CLIENT SEND"); end print("SERVER INCLUDED - "..v); elseif FILTER == "cl_" then AddCSLuaFile(SOURCE.."/"..v); print("CLIENT SEND ONLY - "..v); end elseif CLIENT then if FILTER == "sh_" or FILTER == "cl_" then include(SOURCE.."/"..v); print("CLIENT INCLUDED - "..v); end end end [/lua] I apologize for asking stupid questions but when I get frustrated I tend to over-think things. [editline]24th November 2013[/editline] So, as you can see, I decided that I wanted to make a few functions to assist my script in loading Plugins even further: [lua] function EVO:FindLuaDirectory(SOURCE) return file.Find("skeleton/gamemode/"..SOURCE.."/*.lua", "LUA"); end function EVO:IncludeLuaFile(SOURCE, name) local FILTER = string.sub(name, 1, 3); if SERVER then if FILTER == "sv_" or FILTER == "sh_" then include(SOURCE.."/"..name); if FILTER == "sh_" then AddCSLuaFile(SOURCE.."/"..name); print("CLIENT SEND"); end print("INCLUDED SERVER FILE - "..name); elseif FILTER == "cl_" then AddCSLuaFile(SOURCE.."/"..name); print("INCLUDED CLIENT FILE - "..name); end end if CLIENT then if FILTER == "sh_" or FILTER == "cl_" then include(SOURCE.."/"..name); print("INCLUDED CLIENT FILE -"..name); end end end function EVO:IncludeLuaFile_ALL(SOURCE) for k, v in pairs(self:FindLuaDirectory(SOURCE)) do EVO:IncludeLuaFile(SOURCE, v); end end EVO:IncludeLuaFile_ALL("Plugins"); [/lua] Unfortunately this method is causing some issues... One file in particular(which was working fine before I added these two helper functions) is causing errors.... Anyone have any idea what would cause an error like this: [code] [ERROR] expected near ')' 1.unkown gamemodes/skeleton/gamemode/plugins/sv_data.lua[/code]? It's odd. I'm doing nothing but setting a table which is defined in a shared folder right above these functions...
Sorry, you need to Log In to post a reply to this thread.