Player Classes Not Working

player_class/player_combine_soldier.lua:
[lua]DEFINE_BASECLASS( “player_default” )

local PLAYER = {}


– See gamemodes/base/player_class/player_default.lua for all overridable variables

PLAYER.WalkSpeed = 1900 // for testing purposes
PLAYER.RunSpeed = 400

function PLAYER:Loadout()

self.Player:RemoveAllAmmo()

self.Player:GiveAmmo( 256,	"Pistol", 		true )
self.Player:Give( "weapon_pistol" )

end

player_manager.RegisterClass( “player_combine_soldier”, PLAYER, “player_default” )[/lua]

shared.lua:
[lua]include(“player_class/player_combine_soldier.lua”);[/lua]

init.lua:
[lua]function GM:PlayerSpawn(ply)
player_manager.SetPlayerClass(ply, “player_combine_soldier”);
end[/lua]

I can print the class of player_combine_soldier and that works fine… what am I doing wrong? Everything here seems flawless. He doesn’t spawn with a pistol and his walk speed/run speed are still the default.

Since you’ve overriden the base gamemode’s PlayerSpawn, the hooks aren’t being run as they should.
Go into gamemode/base/player.lua and make sure you run the same stuff.

In player_combine_solder.lua you don’t need the call to DEFINE_BASECLASS unless you’re going to use the BaseClass upvalue in there as well. But in your init.lua you do need a DEFINE_BASECLASS as what Donkie said is correct. You need to DEFINE_BASECLASS( “gamemode_base”). After you do that in your init.lua just do return BaseClass.PlayerSpawn(self, ply) at the end of your PlayerSpawn hook.

Edit:
Also some more info to take into future reference. Any function style hooks (that aren’t added with hook.Add) will only be called once. Meaning if you override any function hooks it’s now your responsibility to call the previous hooks or duplicated previous code into your current hook. The reason is because you’re creating a function and saving it to a table. For example your GM:PlayerSpawn creates an anonymous function and assigns it to GM/GAMEMODE.PlayerSpawn similar to this:



GM.PlayerSpawn = function(self, player)
    -- self is equal to the table GM when called
    -- and player is the player that is attempting to spawn
end


That code would work in place of GM:PlayerSpawn() but it’s not as pretty. But this both of them still assign a function to GM.PlayerSpawn which there can only be one of. So when the function is called the previous GAMEMODE.PlayerSpawn is no longer being called, that’s why you have to call it (the previous one) yourself. This applies to entities as well when you start messing with baseclasses on them.