Need lots of help

So basicly im making a gamemode and when i try to run it i get an error
“There was a problem opening the gamemode file 'Gamemode/gamemode/init.lua”
So i think this is because of my crappy code if anyone of you have the time i would like you to look at it.


AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "vgui/PLoadout.lua" )

include( 'shared.lua' )

// Serverside only stuff goes here

   Name: gamemode:PlayerLoadout( )
   Desc: Give the player the default spawning weapons/ammo
function GM:PlayerLoadout( pl )

	pl:Give( pl:MainW )
	pl:Give( pl:SecW )
	pl:Give( pl:MeleeW )

function SpawnCake()
	CakeSpawn = {}
	CakeSpawn = ents.FindByClass( "info_cake_spawn" )

	if(CakeSpawn == nil)

		--Insert Error Message


include( 'shared.lua' )

// Clientside only stuff goes here

me = {}
me = LocalPlayer()

--Setup player vars

me:MainW = {}
me:SecW = {}
me:MeleeW = {}

me:MainW = "weapon_shotgun"
me:SecW = "weapon_pistol"
me:MeleeW = "weapon_crowbar"

I won’t bother with shared.lua cuz i don’t think there is a problem there,
one of the things im most worried about is the way i call variables like “me” and not only try to use them cross multiple lua files but also try to declare them as a part of the player(so i can have one copy for each player)

Anyway, any help from you guys would be appreciated. :stuck_out_tongue:

  1. Generally it’s helpful if you post the actual error message instead of just “ERROR NOT WORKING”.
  2. You access variables on the player with a period “.” rather than a colon “:”. You use colons for calling functions on the player.
  3. You can’t place variables on an entity on the client (I don’t think, anyway), and even if you could you can’t access those on the server. So, when you try pl:Give( pl:MainW ) it fails first because it’s the wrong syntax and second because you can’t access the clientside variable.

This syntax is invalid. It should be. me.MainW
If you want to add something to a table use **[Table.insert](**.

Also note that variables you define clientside (cl_init.lua) will not be accessible serverside(init.lua).

Doh Entoros already said most of that… But I’ll correct you Entoros : Due to the nature of lua you can place variables on absolutely anything, anywhere in any state.

[editline]1[/editline] [editline]1[/editline]

Thanks guys that really helped me moving on with the code : P


One quick question, if i want to change the me.MainW var on a player, then i need to get the local player, as far as i know i cant use the LocalPlayer() func outside the cl_init, so how do i change the var if i can only change it in init but can only access the player’s var in cl_init basicly how do i find the player executing the function in init and change a variable?

You’d want to set those 3 weapon variables serverside. If you want the player to be able to change his loadout, make a console command on the server that changes the variable.