• getting a steamid and using it as ply:
    18 replies, posted
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.
[QUOTE=Robotboy655;44787780]loop through all players and do string.find test.[/QUOTE] And then how do i use that ply:? can you give an example please?
Try this. [CODE] 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) [/CODE]
[QUOTE=Winter;44787866]Try this. [CODE] 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 end) [/CODE][/QUOTE] Don't do exact compare, it is way to annoying for end user to deal with: [code] for k,v in pairs ( player.GetAll() ) do if string.find( v:Name(), args[1] ) then v:ChatPrint( "It's working." ) end end [/code] [editline]12th May 2014[/editline] And you forgot one end there.
[QUOTE=Robotboy655;44787876]Don't do exact compare, it is way to annoying for end user to deal with: [code] for k,v in pairs ( player.GetAll() ) do if string.find( v:Name(), args[1] ) then v:ChatPrint( "It's working." ) end end [/code] [editline]12th May 2014[/editline] And you forgot one end there.[/QUOTE] 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]
[QUOTE=SarahKerrigan;44790356].... [lua] local _Player.tableForPrint = {}; [/lua][/QUOTE] Just in case anyone was wondering ... No, you can't make a local entry into a table.
[QUOTE=SarahKerrigan;44790356]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][/QUOTE] Acecool?
[QUOTE=Haskell;44792447]Acecool?[/QUOTE] People are starting to listen to him ( oh dear! :v: ) [img]http://puu.sh/8JU1g.png[/img]
[QUOTE=SarahKerrigan;44790356]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][/QUOTE] Please! Don't be used to write everything with [B]_[/B] You can program without any problem, just don't be used to it...
[QUOTE=gonzalolog;44793541]Please! Don't be used to write everything with [B]_[/B] You can program without any problem, just don't be used to it...[/QUOTE] Wait, I thought underscores make you more professional.
Sorry, you need to Log In to post a reply to this thread.