PlayerComponent

Represents a player and provides related function.

# Properties

[{"index":"integer Hp (Sync) (HideFromInspector)","0":"Current Hp."}]

[{"index":"integer MaxHp (Sync)","0":"Maximum Hp."}]

[{"index":"string Nickname (Sync) (HideFromInspector)","0":"Nickname of the player."}]

[{"index":"string ProfileCode (Sync) (ReadOnly) (HideFromInspector)","0":"The player's profile code."}]

[{"index":"boolean PVPMode (Sync)","0":"Sets whether players can attack each other."}]

[{"index":"float RespawnDuration (Sync)","0":"The amount of time to respawn after dying."}]

[{"index":"Vector3 RespawnPosition (Sync) (HideFromInspector)","0":"Sets the location to respawn. If not specified, the SpawnLocation is set as the top priority while the point of the map entrance is set as the second priority."}]

[{"index":"number RespawnTime (Sync) (HideFromInspector)","0":"The expected time to respawn."}]

[{"index":"string UserId (Sync) (ReadOnly) (HideFromInspector)","0":"A unique identifier for the player. It can be used in the targetUserId parameter of the Client execution space control function."}]

##### inherited from Component:

[{"index":"boolean Enable (Sync)","0":"Checks whether Component is activated or not."}]

[{"index":"boolean EnableInHierarchy (ReadOnly) (HideFromInspector)","0":"Displays whether this Component is Enable in the hierarchy. If Entity Enable is false regardless of Component Enable, returns false."}]

[{"index":"Entity Entity (ReadOnly)","0":"The Entity that owns this component."}]

# Methods

[{"index":"boolean IsDead()","0":"Returns whether the player is dead or not."}]

[{"index":"void MoveToEntity(string entityID) (Server) (ScriptOverridable)","0":"Moves the player to the same location as an Entity corresponding to the entityID or to another map if the entityID belongs to it."}]

[{"index":"void MoveToEntityByPath(string worldPath) (Server) (ScriptOverridable)","0":"Moves the player to the same location as an Entity in the worldPath, or another map if the worldPath points to it."}]

[{"index":"void MoveToMapPosition(string mapID, Vector2 targetPosition) (Server) (ScriptOverridable)","0":"Moves the player to a specific location on a specific map."}]

[{"index":"void ProcessDead(string targetUserId = nil) (Client)","0":"Causes the player to die."}]

[{"index":"void ProcessRevive(string targetUserId = nil) (Client)","0":"Revives player."}]

[{"index":"void Respawn() (ScriptOverridable)","0":"Performs a respawn. For the Respawn position, RespawnPosition is the first priority, SpawnLocation in the map is the second, and the point of map entrance is the third."}]

[{"index":"void SetPosition(Vector3 position)","0":"Sets an Entity's position based on local coordinates."}]

[{"index":"void SetWorldPosition(Vector3 worldPosition)","0":"Sets the Entity position in world coordinates."}]

##### inherited from Component:

[{"index":"boolean IsClient()","0":"Returns whether the current execution environment is a client or not."}]

[{"index":"boolean IsServer()","0":"Returns whether the current execution environment is a server or not."}]

# Examples

Changes the respawn position to the object's position while touching an object named "Check Point". To see if the respawn position has changed, touch an object named "Do Not Touch", which kills the player.
    
    
    @Component
    script CheckpointHazardHandler extends Component
        @ExecSpace("ServerOnly")
        @EventSender("Self")
        handler HandleTriggerEnterEvent(TriggerEnterEvent event)
        -- Parameters
        local TriggerBodyEntity = event.TriggerBodyEntity
        --------------------------------------------------------
    
        local player = self.Entity.PlayerComponent
    
        if TriggerBodyEntity.Name == "Check Point" then
            player.RespawnPosition = TriggerBodyEntity.TransformComponent.Position
        elseif TriggerBodyEntity.Name == "Do Not Touch" then
            self.Entity.PlayerComponent:ProcessDead()
        end
        end
    end
    

# SeeAlso

  * TriggerComponent
  * TriggerEnterEvent
  * [Setting and Controlling Player](/docs?postId=547)