Guys.. this is getting annoying ;-;

Just to clarify, I am not a complete noob in Glua.

Now, this may sound pathetic but I am struggling to understand how the inclusion of files works. I see gamemodes that don’t even use the “AddCSLuaFile” function which doesn’t really make sense and makes the function redundant. I find myself getting ‘Missing File’ errors when the file does exist and is not empty with no errors within it. Help with ensuring I’m understanding the system would be greatly appreciated as I have faced this in all gamemodes I have made finding myself wiping the gamemode to fix this annoying occurrence.

Errors I get:


[name|2|STEAM_0:1:54150875] Lua Error:
Couldn't include file 'core.lua' (File not found) (@gamemodes/asparagus/gamemode
/cl_init.lua (line 1))

[name|2|STEAM_0:1:54150875] Lua Error:
Couldn't include file 'cl_hud.lua' (File not found) (@gamemodes/asparagus/gamemo
de/cl_init.lua (line 2))

try creating five more threads about this it might help

As said before, take a look at this: https://dl.dropboxusercontent.com/u/26074909/tutoring/includes/gm_name.rar

Put all includes and AddCSLuaFile calls in sh_init.

Now, to clarify… AddCSLuaFile is called on the SERVER so the SERVER knows which files to send to the CLIENT… The CLIENT can NOT include files unless they were AddCSLuaFile’d by the SERVER first!

If you use the gm_name.rar system, you can simply use IncludeFiles function starting from the // SHARED comment lines and below.

The 3 REALM_* variables are called ENUMerationS because we give the name “value” instead of the actual value. We use Enumeration so that it increases readability. Other variables that are all upper case are called CONSTantS because the value should never change; these give “value” to the value because the value is useful in some way such as converting in-game units to real-life sizes… The variables don’t need to be all upper-case but in most coding-standards they are…

So, using IncludeFiles( _file, _realm ); from my gm_name.rar file lets you simplify how you include files… If you want the file to be SHARED ( meaning both the CLIENT and SERVER include it ) then you set the _realm argument to REALM_SHARED; this is where you put SHARED hooks, functions that are used in both CLIENT and SERVER code, etc… If you only want the CLIENT to download and include the file, you set _realm to REALM_CLIENT; this is where you put CLIENT-side hooks, HUDs, etc… If you only want the SERVER to include it then you use REALM_SERVER; this is where you’d put SERVER-side hooks and code that only the SERVER should see.


//
// SHARED
//
IncludeFiles( "shared/sh_player.lua", REALM_SHARED );
IncludeFiles( "shared/gm_createteams.lua", REALM_SHARED );


//
// CLIENT
//
IncludeFiles( "client/hud/cl_hud.lua", REALM_CLIENT );


//
// SERVER
//
IncludeFiles( "server/sv_admin.lua", REALM_SERVER );


//
// ADDONS
//
IncludeFiles( "addons/drowning.lua", REALM_SHARED );


//
// CONTENT
//
IncludeFiles( "content/maps/" .. _map .. "/config.lua", REALM_SHARED );
IncludeFiles( "content/maps/" .. _map .. "/spawn_points.lua", REALM_SERVER );
	

Using a helper-function like IncludeFiles will makes things a lot easier. Also, because everything is included in the sh_init.lua file, it helps better understand the FLOW of code… Here’s an example of BAD file-inclusion which will only work if the server is loaded and then auto-refreshed: https://dl.dropboxusercontent.com/u/26074909/tutoring/includes/file_only_works_on_autorefresh_possible_reasons.lua.html – this is because some helper function or variable was defined AFTER it was needed ( in some cases it’ll throw an error and won’t continue until you fix the code ).

Imagine the CLIENT and SERVER are 100% independent of each-other ( which they are ) and both CLIENT and SERVER read the same file sh_init.lua included… The different realms will use different versions of the file which is to say they won’t execute the same code but because it is SHARED they both see the same code / file… The SERVER and CLIENT execute the code one line at a time as it appears… When an include is seen it stops loading the file where include was put then grabs the file it should include and runs that line by line… After the included file has been processed code execution continues in the first file where include was at the next line…

Hopefully this clarifies things; and I’d highly recommend using the helper-function / files I zipped in gm_name.rar ( then copy your game-mode files into folders and remove all in gm_name except your data and cl_init.lua, sh_init.lua and init.lua… make sure you don’t copy your init.lua, shared.lua and cl_init.lua to the gamemode/ directory but move the contents of functions / function GM: etc into other files ). If you need help setting it up, add me on Steam and I’ll help you set it up to give you an easier time.