Lua Error - Creating Classes

I’m trying to learn more lua, and have begun learning about classes.
Basically, when I try to make a class, I get this error:

Function CreateMove not found on player class!
Function CalcView not found on player class!
Function ShouldDrawLocal not found on player class!
Function CreateMove not found on player class!
Function StartMove not found on player class!
Function Move not found on player class!
Function FinishMove not found on player class!

Here’s my code for creating the classes:

team.SetUp( 1, 'Guards', Color( 220, 110, 110 ) )
team.SetUp( 2, 'Prisoners', Color( 110, 110, 220 ) )

local GuardClass = {}
	GuardClass.WalkSpeed = 500
	GuardClass.RunSpeed = 1000
	GuardClass.MaxHealth = 250
	GuardClass.StartHealth = 250
	GuardClass.TeammateNoCollide = true
	GuardClass.JumpPower = 2000
	GuardClass.WepLoadout = function( info )
		info.Player:Give( 'weapon_stunbaton' )
		info.Player:Give( 'weapon_357' )
		info.Player:ChatPrint( 'Go get those Prisoners!' )
local PrisonerClass = {}
	PrisonerClass.WalkSpeed = 500
	PrisonerClass.RunSpeed = 1000
	PrisonerClass.MaxHealth = 250
	PrisonerClass.StartHealth = 250
	PrisonerClass.TeammateNoCollide = true
	PrisonerClass.JumpPower = 2000
	PrisonerClass.WepLoadout = function( info )
		info.Player:Give( 'weapon_crowbar' )
		info.Player:Give( 'weapon_pistol' )
		info.Player:ChatPrint( 'You gotta escape before being caught!' )
player_manager.RegisterClass( 'guardclass', GuardClass, 'defaultguard' )
player_manager.RegisterClass( 'prisonerclass', PrisonerClass, 'defaultprisoner' )

And here’s where the class is called in the init.lua:

function GM:PlayerSpawn( ply )

	player_manager.SetPlayerClass( ply, 'guardclass' )
	player_manager.OnPlayerSpawn( ply )
	player_manager.RunClass( ply, 'WepLoadout' )

Ideally, I’d like to have players put into a random class, with some balancing, but I’d rather get them working seperately first. If I can’t get this working, then I can’t continue. Help?

Show us the defaultguard and defaultprisoner classes.

There isn’t any.
I’m a lua noob, and was never told what to put in there, all the tutorials said nil, which also didn’t work so I didn’t think it mattered.
That’s just something random when I thought it was asking me for a variable.

Alright, the third argument to player_manager.RegisterClass is what the class should base from. It might be a good idea to base it off of ‘player_default’ as that comes with the default (usually empty) functions so you do not need to do that yourself. The error is complaining that functions like “CreateMove” do not exist in your player class but if you base from player_default, this is all done for you.

As a side note, it would be better to call your “WepLoadout” function “Loadout” to be consistent with, and to override, the player_default class:

I hate when I have to admit stupid mistakes, but people like you make it all worthwhile, thanks man. I’ll try this and see how it turns out.

[editline]11th April 2015[/editline]

Ok, that part worked, but I’m still wondering about one more thing.
I want to write on a HUD the class the player is in. I did this previously using a simple:

if ply:Team() == (teamnamehere) then

I used this when I created the teams using team.SetUp and no classes. I still have used team.SetUp in my code (as seen in my code above), but it’s not working this time.
I’m guessing my class isn’t linked to the team or something, and that’s probably why it’s not working, but I don’t know how to fix this.
(I may have worded that badly, I’m over complicating things.)

You would still need to call ply:SetTeam(team_id_here). You could do this in the class though. Alternatively if you want a player class only system then you could compare player_manager.GetPlayerClass(ply).

[lua]if player_manager.GetPlayerClass(ply) == “guardclass” then[/lua]

How would I link the class and team, so that calling the team in commands like ply:Team() and team.NumPlayers() would return the people in that class. Because right now, it seems that my team.SetUp isn’t doing anything, and it would be useful in team balancing etc.

EDIT: Nevermind, I worded that really badly but figured out a solution anyways. Thanks for all the help :slight_smile:

Call ply:SetTeam with the team ID. You can do this in the class itself so that everyone with that class is on the given team.