UserService

Provides user-related function.

# Properties

[{"index":"Entity LocalPlayer (ReadOnly)","0":"This is My Player. Available only on the client."}]

[{"index":"ReadOnlyDictionary UserEntities (ReadOnly)","0":"A list of all user entities. key is the user Id, and value is the user entity."}]

[{"index":"ReadOnlyDictionary Users (ReadOnly)","0":"A list of all users' information. key is the user Id, and value is the user information."}]

# Methods

[{"index":"string GetUserBanReason(string profileCode) (ServerOnly) (ReleaseOnly)","0":"Checks the sanction reason of a sanctioned user via World Insight. Operates only in the release environment."}]

[{"index":"User GetUserByProfileCode(string profileCode)","0":"Finds and returns the user information that corresponds to profileCode."}]

[{"index":"int32 GetUserCount()","0":"Returns the current number of users."}]

[{"index":"Entity GetUserEntityByUserId(string userId)","0":"Finds and returns the user with the corresponding userId."}]

[{"index":"table GetUsersByMapComponent(MapComponent mapComponent)","0":"Finds and returns users that belong to the map corresponding to mapComponent."}]

[{"index":"table GetUsersByMapName(string mapName)","0":"Finds and returns users that belong to the map corresponding to mapName."}]

[{"index":"boolean IsUserBanned(string profileCode) (ServerOnly) (ReleaseOnly)","0":"Checks whether the user is sanctioned via World Insight. Operates only in the release environment."}]

[{"index":"void KickUser(string userId, KickReason kickReason) (ServerOnly)","0":"Exile the user corresponding to userId. The expelled user is informed that he has been deported for reasons corresponding to kickReason."}]

##### inherited from Service:

[{"index":"EventHandlerBase ConnectEvent(string key, IScriptFunction eventHandler)","0":"Links events. When a key-type event occurs in this service, a handler is notified. The handler receives event parameters."}]

[{"index":"EventHandlerBase ConnectEvent(Type eventType, IScriptFunction eventHandler)","0":"Links events. This service notifies a handler when an eventType event occurs. The handler receives event parameters."}]

[{"index":"boolean DisconnectEvent(string key, EventHandlerBase eventHandler)","0":"Disconnects the event with the key-type event and the handler."}]

[{"index":"boolean DisconnectEvent(Type eventType, EventHandlerBase eventHandler)","0":"Disconnects the eventType event from its handler."}]

[{"index":"void SendEvent(EventType sendEvent)","0":"Generates an event."}]

# Events

[{"index":"UserDisconnectEvent","0":"This event occurs when the user's network connection is unstable or disconnected."}]

[{"index":"UserEnterEvent","0":"This event occurs in UserService when a user enters a game."}]

[{"index":"UserKickEvent","0":"The event occurs when a user is expelled. Can only occur on the server."}]

[{"index":"UserLeaveEvent","0":"This event occurs in UserService when a user leaves.\\\nThe User Entity will be deleted once the UserLeaveEvent handler is complete.\\\nIf the UserLeaveEvent handler takes too long, the user Entity will be deleted first."}]

[{"index":"UserReconnectEvent","0":"This event occurs when the user reconnects."}]

# Examples

The following is an example of changing the NameTag to prevent users from knowing each other's nicknames.

UserId is used to determine the word and color of the NamgTag when a user enters.
    
    
    @Component
    script UserRoleNametagSetter extends Component
        @ExecSpace("ServerOnly")
        @EventSender("Service", "UserService")
        handler HandleUserEnterEvent(UserEnterEvent event)
        -- Parameters
        local UserId = event.UserId
        --------------------------------------------------------
    
        local userEntity = _UserService:GetUserEntityByUserId(UserId)
        local nametag = userEntity.NameTagComponent
    
        if UserId == "000000" then
        	nametag.Name = "Admin"
        	nametag.FontColor = Color.magenta
        else
        	nametag.Name = "Player"
        	nametag.FontColor = Color.cyan
        end
        end
    end
    

# SeeAlso

  * NameTagComponent
  * UserEnterEvent
  * Color