getting a steamid and using it as ply:

Lets say i sent a string of a nickname, And i want to use the players class with ply:…
How would I use the players ply class?

Could you explain what you mean?

I am sending a players nickname from client side to server side, and I i want to use that nickname and send to it a private message for example with: ply:PrintMessage, But first i’ll need to get the players nickname and compare it with the ply’s class name some how in order to use the ply:PrintMessage, So it’ll know which player to send the message to.

loop through all players and do string.find test.

And then how do i use that ply:? can you give an example please?

Try this.

concommand.Add("sendtest", function(ply, cmd, args) -- Put 'sendtest YourNickname' in console.

	for k,v in pairs ( player.GetAll() ) do
		if v:Name() == args[1] then
		v:ChatPrint( "It's working." )
                end -- Oops.


Don’t do exact compare, it is way to annoying for end user to deal with:

for k,v in pairs ( player.GetAll() ) do
    if string.find( v:Name(), args[1] ) then
         v:ChatPrint( "It's working." )

[editline]12th May 2014[/editline]

And you forgot one end there.

First of all thanks :P,
So now ‘v’ is my ply class?
Because i do need it as my ply class :P.

Yes. ply isn’t a class, it is a common variable name for Player class.

You can call it whatever you want. Just as long it’s consistent to when it’s declared (in this case, in the for line)

for k,melon in pairs(player.GetAll()) do
if string.find(melon:Name(), args[1]) then
melon:ChatPrint(“It’s working.”)

ok, and is there anyway of adding some variables to the player class?

ply.variable = “whatever”

And will it save it until the player loggs off?

This is a bit how it works.

[lua]function testFunction(_Player)

if ( _Player:IsValid() ) then
	ply = _Player:SteamID();

hook.Add(“PlayerSpawn”, “testFunction” testFunction)

function customFunction(_Player)

local _Player.tableForPrint = {};
_Player.testVariable = 1;
_Player.tableForPrint.hi = "hi";
_Player.tableForPrint.message = "message";


Just in case anyone was wondering … No, you can’t make a local entry into a table.


People are starting to listen to him ( oh dear! :v: )

Please! Don’t be used to write everything with _
You can program without any problem, just don’t be used to it…

Wait, I thought underscores make you more professional.