How do you get a player from their name.
#1
The question is as the title says.
Reply
Thanks given by:
#2
local Callback = function(Player)
Player:SendMessage("Info")
end
cRoot:Get():FindAndDoWithPlayer("PlayerName", Callback)
I think that should do it.
Reply
Thanks given by:
#3
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.
Reply
Thanks given by:
#4
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?
Reply
Thanks given by:
#5
You cannot do that, because it would not be threadsafe
Reply
Thanks given by:
#6
The server uses callbacks because if you would use cWorld::GetPlayer() the player object might change while you are changing stuff.
Reply
Thanks given by:
#7
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.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)