Get user's id?

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Aiidenb
Posts: 263
Joined: 16 Aug 2010, 22:08
Location: England
Contact:

Get user's id?

Postby Aiidenb » 04 May 2014, 18:12

Hello!
This is a pretty basic question, but i've searched a lot for it and I can't seem to find a basic answer.

I have a button in which performs a ban function on press.

The function:

Code: Select all

function banUser(username){
         var dataObj:Object = {};
         dataObj.id = userId.toString()
   dataObj.msg = "You have been banned by an online moderator.";
   dataObj.mode = "0";
   smartFox.sendXtMessage("$dmn","ban",dataObj);
   trace(username + " has been banned.");
}

The button calls the players username;

Code: Select all

on(release){
_root.banUser("test");
}

Is there any possible way I can retrieve the user's ID from just their username?
Or in another case, if their anyway to ban a user from their username?
Thanks in advance. :)
Quackbay - The online virtual world for kids!
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Get user's id?

Postby Bax » 05 May 2014, 08:19

From the Room object you can get the User object you need by means of the Room.getUser method (passing the username as the parameter).
Then on the User object you can get his id by mens of the User.getId method.
Paolo Bax
The SmartFoxServer Team
Aiidenb
Posts: 263
Joined: 16 Aug 2010, 22:08
Location: England
Contact:

Re: Get user's id?

Postby Aiidenb » 05 May 2014, 15:55

Thanks for the reply!

However, i'm still not really understanding a method in coding-wise.
Would you mind giving me an example?

Thanks, Aiden. :)
Quackbay - The online virtual world for kids!
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Get user's id?

Postby Bax » 06 May 2014, 09:01

Code: Select all

var room:Room = smartFox.getRoomByName(roomname);
var user:User = room.getUser(username);
var userId:int = user.getId();
Paolo Bax
The SmartFoxServer Team

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 65 guests