How to make your own class type thing, like ply:IsReady() etc etc

I did a bit of c#, and I was wondering is there anyway to make something like ply:IsReady() to check if they are ready to start game, etc etc?
And to make classes and stuff, google is telling me that lua is like semi object oriented

Lookup the Player metatable, then attach a function to that.
[lua]PLAYER = FindMetaTable( “Player” );

function PLAYER:IsReady( )


Yeah for sure! It’s not that hard actually.

Basically this is done by adding to the player metatable. A metatable is a table of functions that can only be performed on certain objects. In this case you’ll want to use the player metatable. So your code will look something like this:

local ply = FindMetaTable( "Player" )
if !ply then return end

function ply:your_function_name( args_go_here ) -- the varaible 'self' is the player the function is being run on. it works like any player object.
	-- do whatever logic you'd like inside the function
	print( self:Name() ) -- some examples of using the self object
	print( self:SteamID() )
	self:ChatPrint( args_go_here )

--Example usage:

for _, ply in ipairs( player.GetAll() ) do
	ply:your_function_name( "haha!" )

Thanks everyone :smiley:
Alot easier then I assumed

[editline]19th January 2014[/editline]

Okay, so this was solved, but I have a question not worth starting a thread and related to this,

How do I have a variable on that one player, example, i want to see if they are ready, this is my code

ready = false
function GM:ShowSpare1( ply )
	ply:IsReady(not ready)
	for k,v in pairs (player.GetAll()) do
		if (players > 1 and not gameStarted and v:IsReady()) then

function ply:IsReady( ready ) 
	print( self:Name() ) 
        if(ready == true)
		PrintMessage( HUD_PRINTTALK, self:GetName().." is ready." )
        if(ready == false)
        	PrintMessage( HUD_PRINTTALK, self:GetName().." isn't ready." )

I need it so, it is a toggle “true and false” and that when every player is ready (true) then it starts,
What am I doing wrong?

In the code to set if they’re ready, set
[lua]ply.ready = true[/lua]

then for ply:IsReady all you have to do is
[lua]if (self.ready) then
PrintMessage( HUD_PRINTTALK, self:GetName()…" is ready." )
PrintMessage( HUD_PRINTTALK, self:GetName()…" isn’t ready." )

Don’t use any arguments for IsReady.