Server and Client side file setup

I’m having some problems with my client-side file not running.

I’ve got

addons/sgn_darkrpmod/lua/autorun/server/sv_init.lua
addons/sgn_darkrpmod/lua/sv_playerlogin.lua
addons/sgn_darkrpmod/lua/cl_playerlogin.lua

sv_init includes sv_playerlogin.lua and that works fine, it prints that it has started.
However my cl_playerlogin doesn’t seem to be working.

What is the proper way to make sure cl_playerlogin is included with the client and what else do I need to do.

So far I’ve got include("…/…/sv_playerlogin.lua") in my sv_init.lua and sv_playerlogin.lua does include fine.

Then in sv_playerlogin.lua I’ve got : AddCSLuaFile( “cl_playerlogin.lua” ). Below is my sv_playerlogin.lua and when I log-in it does print “This has worked no 3” so I know the login works but… see below



print( "playerlogin.lua has been loaded." )

AddCSLuaFile( "cl_playerlogin.lua" )

util.AddNetworkString( "characterCreationScreen" )
util.AddNetworkString( "characterSelectionScreen" )

function playerExist( ply )
    local steamID = ply:SteamID()
    local playerFound = sql.QueryValue( "SELECT * FROM characterdata WHERE unique_id = '" .. steamID .. "'" )
    if playerFound != nil then
        return true
    else
        return false
    end
    print(tostring(playerFound))
end

local function playerLogin( ply )

	timer.Simple( 15, function()
		print("This has worked no 1")

		print(tostring( playerExist(ply) ))

		if playerExist( ply ) == false then
			
			net.Start( "characterCreationScreen" )
			net.Broadcast()
			print("This has worked no 2")

		else

			net.Start( "characterCreationScreen" )
			net.Broadcast()
			print("This has worked no 3") // this is the latest bit that happens, so it does get this far.

		end
	end )
	
end
hook.Add( "PlayerInitialSpawn", "playerLogin", playerLogin )

print("playerlogin.lua has been loaded." )


but it doesn’t seem to send the net.Start as I don’t get the print from in cl_playerlogin.lua in the client console. Am I doing something wrong when including this file?

cl_playerlogin.lua



net.Receive( "characterCreationScreen", function()
	print("This has worked no 4.5")
end )


I suggest you name your files more uniquely so other addons may not interfere with yours. Add a prefix or postfix to your files in autorun, and put the rest of the files into a directory, like lua/autorun/sgn_init.lua and lua/sgnmod/*.lua or something.

Ok, I’ll do that. But do you know why my client file would not be including?

I’ll change all the names now.

Try calling AddCSLuaFile in the autorun file.

Thanks, I’ll do that. Is it true you also need to include the client-side file client-side. So do I need to include cl_playerlogin.lua in cl_playerlogin.lua? Or something like that.

Also, is include relative to the current directory, but AddCSLuaFIle relative to the lua directory? As I’ve read some very mixed things.

Uh, not exactly. I haven’t noticed that you don’t include the cl file at all. Move your autorun file from autorun/server to autorun/, add necessary checks and include the cl file from the autorun file.

You must include the file from another clientside file, but not from itself.

You shouldn’t be doing net.Broadcast() because that send’s it to all players. This is wasn’t tested but it’s a much cleaner way of doing things.

[lua]
print(“playerlogin.lua has been loaded.”)

AddCSLuaFile(“cl_playerlogin.lua”)

util.AddNetworkString(“ply_CharCreationScreen”)
util.AddNetworkString(“ply_CharSelectionScreen”)

local DB = {}

DB.PlayerExists = function(self, ply)
local pSteamID = ply:SteamID()
return sql.QueryValue(“SELECT * FROM characterdata WHERE unique_id = '” … pSteamID … “’”)
end

DB.PlayerInitialSpawn = function(self, ply)
timer.Simple(1, function()
if self:PlayerExists(ply) then
net.Start(“ply_CharSelectionScreen”)
net.Send(ply)
else
net.Start(“ply_CharCreationScreen”)
net.Send(ply)
end
end)
end
hook.Add(“PlayerInitialSpawn”, “DB_CharCreation.PISpawn”, function(…) DB:PlayerInitialSpawn(…) end)
[/lua]

Thank you, yes I know about broadcast I only put it there as a test. At the moment I’m just trying to find out why it won’t include the client file, however I will take a look at what you’ve done as i’m sure I can use somethings from it.

As for the autorun init file:



if SERVER then
	
	SGNDarkRP = {}
	SGNDarkRP.Config = {}
	SGNDarkRP.Config.Dev = {}
	SGNDarkRP.Config.Client = {}
	SGNDarkRP.Config.Misc = {}
	SGNDarkRP.Config.Server = {}

	//Prints debut text to the console
	function debugText( message )
	    if debugEnabled == true then
			print( "[DEBUG] " .. message )
	    end
	end

	print("=========================================================")

	include("../sgn_settings/config.lua")

	include("../sgn_databases.lua")

	include("../sgn_modules/playerlogin/sv_playerlogin.lua")
	AddCSLuaFile("../sgn_modules/playerlogin/cl_playerlogin.lua")

	print("=========================================================")


end

if CLIENT then

	include( "../sgn_modules/playerlogin/cl_playerlogin.lua" )

end


I keep getting the error:

Couldn’t include file ‘…\sgn_modules\playerlogin\cl_playerlogin.lua’ (File not found) (@addons/sgn_darkrpmod/lua/autorun/sgn_init.lua (line 36))

I keep trying different path types such as /sgn_modules …/sgn_modules sgn_modules/ etc and it just doesn’t want to include it. I’m sure I’m just doing something stupid.

New filepaths are addons/sgn_darkrpmod/autorun/sgn_init.lua which is what the above code is from. Then sgn_darkrpmod/modules/playerlogin/ which holds cl_playerlogin.lua and sv_playerlogin.lua.

filepaths: garrysmod/addons/sgn_darkrpmod/lua/sgn_modules/playerlogin/sv_playerlogin.lua
filepaths: garrysmod/addons/sgn_darkrpmod/lua/sgn_modules/playerlogin/cl_playerlogin.lua
filepaths: garrysmod/addons/sgn_darkrpmod/lua/autorun/sgn_init.lua

Put AddCSLuaFile() at the top of your autorun file to make it run the clientside portion.

Thanks for your reply, I just tried that put it didn’t seem to make any difference. However I believe it is running the CLIENT portion as I get the error:

Couldn’t include file ‘…\sgn_modules\playerlogin\cl_playerlogin.lua’ (File not found) (@addons/sgn_darkrpmod/lua/autorun/sgn_init.lua (line 38))

When the player logs in. Which makes it seem as though it’s trying to include it, but can’t find it?

[editline]8th June 2014[/editline]

Yes, it is running it. As I put a print(“test”) in the client part and when I log-in I do get test in my console.

Use full paths, damn you. You are making life harder for both of us.

I just tested my own addon and I can include and AddCSLuaFile just fine.

addons/AddonIncludeTest/lua/autorun/myaddon_init.lua
[lua]
if SERVER then
AddCSLuaFile()
AddCSLuaFile(“test_path/settings/cl_config.lua”)
include(“test_path/settings/sv_config.lua”)
else
include(“test_path/settings/cl_config.lua”)
end
[/lua]

addons/AddonIncludeTest/lua/test_path/settings/sv_config.lua
[lua]
print(“SERVER config loaded”)
[/lua]

addons/AddonIncludeTest/lua/test_path/settings/cl_config.lua
[lua]
print(“CLIENT config loaded”)
[/lua]

Thank you, I have followed both of yours advice to use full paths instead of relative and it is now working. I’ll use the if SERVER else end now instead of two separate files, and now understand how includes clientside and serverside work.

Thank you for testing that yourself brandon.