getting a steamid and using it as ply:

Hello.
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?

Ok.
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.
		
	end

end)



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." )
    end
        
end


[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)

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

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();
	customFunction(ply)

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

function customFunction(_Player)

local _Player.tableForPrint = {};
_Player.testVariable = 1;
print(_Player.testVariable);
_Player.tableForPrint.hi = "hi";
_Player.tableForPrint.message = "message";
PrintTable(_Player.tableForPrint);

end
[/lua]

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

Acecool?

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

http://puu.sh/8JU1g.png

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.