08-07-2013, 12:59 AM
The question is as the title says.
How do you get a player from their name.
|
08-07-2013, 12:59 AM
The question is as the title says.
08-07-2013, 01:04 AM
local Callback = function(Player) Player:SendMessage("Info") end cRoot:Get():FindAndDoWithPlayer("PlayerName", Callback)I think that should do it. Thanks given by: bearbin
As usual, due to multithreading, you cannot get the cPlayer object directly, you can only have a callback be called on it, exactly as STR wrote.
There's even a hackier way to write this in Lua: cRoot:Get():DoWithPlayer("PlayerName", function(a_Player) a_Player:SendMessage("Info"); end ); Note that there are two similar functions, DoWithPlayer() and FindAndDoWithPlayer(). The first one requires an exact username match, the second one uses the closest username (you might want to check the username in the callback). I'm not sure now what exactly matches, but I believe substrings do, maybe even one-letter typos. Oh, wait, the DoWithPlayer() seems to be implemented only on cWorld, not on cRoot. But you should be calling them on a cWorld anyway, since you probably know, which world the player is at. Thanks given by: bearbin
08-27-2013, 02:04 AM
Reading through the API section of the wiki, it says there's cWorld:GetPlayer() which takes a player name and gives you a cplayer. Would this be an alternative to ugly callbacks?
08-27-2013, 02:15 AM
You cannot do that, because it would not be threadsafe
Thanks given by: NiLSPACE
The server uses callbacks because if you would use cWorld::GetPlayer() the player object might change while you are changing stuff.
08-27-2013, 06:17 AM
The cWorld section of the wiki is probably the most outdated thing on that wiki. It desperately needs improving, but it's so huge that no-one has been daring enough to actually do it.
|
« Next Oldest | Next Newest »
|