Using Server AND Client functions in same file?

So I have a code and I want to be able to do this code in the file instead of screwing with the init.lua ( SVN Problems ):
[lua]
function GM:PlayerInitialSpawn( ply )
if ply:IsUserGroup( “user” ) or ply:IsUserGroup( “VIP” ) then
umsg.Start( “ClientReport” );
umsg.End();
else
umsg.Start( “AdminReport” );
umsg.End();

end

end
[/lua]

So, would I have to do this:
[lua]
if SERVER then
– the function –
end

– and in init.lua include( ‘file name.lua’ )
[/lua] ???

[lua]if SERVER then
–server sided function shit
else
–clientsided shit
end[/lua]

Okay, then I did this:

[lua]
if SERVER then
function GM:PlayerInitialSpawn( ply )
if ply:IsUserGroup( “user” ) or ply:IsUserGroup( “VIP” ) then
umsg.Start( “ClientReport” );
umsg.End();
else
umsg.Start( “AdminReport” );
umsg.End();

	end
end

else – For some reason it ends at the above line ^
[/lua]

Does anyone know why it ends at the second “end” instead of continuing on to the “else” part of the ifstatement?

EDIT:

Nevermind, I solved the problem with NotePad ++… I’m not sure why it wasn’t working.

The SERVER and CLIENT values would only work in a sh_init.lua file

2 Things, when you say sh_init.lua do you mean shared?

What should I do otherwise?

Yes.

Otherwise you don’t need the checks. One file would be a server file(init.lua); the other file would be a client file(cl_init.lua).

So you are saying just make a cl_filename.lua and put all the derma stuff here, AddCSLuaFile( “cl_filename.lua” ) and a filename.lua then include( ‘cl_filename.lua’ ) in the init.lua?

Yup, that would be the way to do it. Except include(“filename.lua”)

Or make one file and make it shared.

And how exactly would I do that other than putting it in the shared.lua

Do this in init.lua:
[lua]include( “sh_init.lua” ) ; – or whatever
AddCSLuaFile( “sh_init.lua” ); – or whatever[/lua]

cl_init.lua:
[lua]include( “sh_init.lua” ); – or whatever[/lua]

Make sure when you’re doing this that things are in the correct folders… I’ve seen way too many people go
“herp derp I named it sv_init.lua and cl_init.lua but it still doesn’t work!”

If its NOT a shared file (meaning just going into lua/addons) then you gotta put them in server/client folders respectively

As in, all files are shared if they aint in a folder called server or client, or they ain’t named cl_init or init.

I’m pretty sure it is like this though lol

This will be in the actual gamemode folder.

Shared files are run by both the server and client, therefore you need to use if CLIENT and if SERVER so that the code will be run by the intended parties. Or you could make separate files for the client and server containing only the code that you want them to run. Either put them in lua/autorun for them to be shared or in lua/autorun/server or /client for them to be run separately.

If you want to put them into a gamemode put them in garrysmod/gamemodeNAME/gamemode/ and then use include("") from the cl_init.lua and/or init.lua .

Also remember, any clientside file needs to be downloaded from the server and included to the client.

So a shared file needs to be downloaded to the client, and included serverside and clientside.

Just to make sure:

AddCSLuaFile (server side) - Adds a client side file to be downloaded
Include (both) - makes which ever side it is in look and run the code

Yea. Just remember any code you put in shared can be seen by the client still.

So I wouldnt put things such as a mysql login.

It’s encrypted now I believe.

Though if your MySQL is properly secured you could give out your password and no one can touch you.

As in, only the local host can access the db.