# SSeat

**Membres** 16

|           |                                         |                                                                                                    |
| --------- | --------------------------------------- | -------------------------------------------------------------------------------------------------- |
| Fonction  | [SitPlayer](#sitplayer)                 | Make a player sit.                                                                                 |
| Fonction  | [UnseatPlayer](#unseatplayer)           | Make a player unseat.                                                                              |
| Fonction  | [OnStandUp](#onstandup)                 | Binds a function to the Seat's On Stand Up event                                                   |
| Fonction  | [OnSit](#onsit)                         | Binds a function to the Seat's On Sit event                                                        |
| Fonction  | [OnPlayerStandUp](#onplayerstandup)     | Binds a function to the Seat's On Player Stand Up event which is fired only on the Player's client |
| Fonction  | [OnPlayerSit](#onplayersit)             | Binds a function to the Seat's On Player Sit event which is fired only on the Player's client      |
| Propriété | [Enabled](#enabled)                     | Whether the seat component is enabled.                                                             |
| Propriété | [InUse](#inuse)                         | Return that whether the seat is in use.                                                            |
| Propriété | [PlayerSeated](#playerseated)           | Return the ID of the seating player.                                                               |
| Propriété | [UseSlotID](#useslotid)                 | Return true if uses SlotID                                                                         |
| Propriété | [SlotID](#slotid)                       | Return the slot ID of the seat.                                                                    |
| Propriété | [ClickableCollider](#clickablecollider) | Return the clickable collider.                                                                     |
| Propriété | [Animation](#animation)                 | Return the animation clip.                                                                         |
| Propriété | [AnimationMale](#animationmale)         | –                                                                                                  |
| Propriété | [AnimationFemale](#animationfemale)     | –                                                                                                  |
| Propriété | [GameObject](#gameobject)               | –                                                                                                  |

## Fonctions

### SitPlayer

void SitPlayer()

Make a player sit.

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Seat.SitPlayer()

```

### UnseatPlayer

void UnseatPlayer()

Make a player unseat.

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Seat.UnseatPlayer()

```

### OnStandUp

void OnStandUp(Closure e)

Binds a function to the Seat's On Stand Up event

Paramètres

| Nom | Type    | Valeur par défaut |
| --- | ------- | ----------------- |
| e   | Closure | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
e = function()
Space.Log("On Stand Up event")
end

Space.Host.ExecutingObject.Seat.OnStandUp(e)

```

### OnSit

void OnSit(Closure e)

Binds a function to the Seat's On Sit event

Paramètres

| Nom | Type    | Valeur par défaut |
| --- | ------- | ----------------- |
| e   | Closure | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
e = function()
Space.Log("On Sit event")
end

Space.Host.ExecutingObject.Seat.OnSit(e)

```

### OnPlayerStandUp

void OnPlayerStandUp(Closure e)

Binds a function to the Seat's On Player Stand Up event which is fired only on the Player's client

Paramètres

| Nom | Type    | Valeur par défaut |
| --- | ------- | ----------------- |
| e   | Closure | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
e = function()
Space.Log("On Player Stand Up")
end

Space.Host.ExecutingObject.Seat.OnPlayerStandUp(e)

```

**Lua**

```lua
--the below script will teleport the player above the seat after standing up
--so that they do not go back to original position, but rather be standing next to the seat
--(Example: if the seat moves - such as in a vehicle- and we want to stand up next to it)
--[Requires Seat Component in the GameObject running this script]

thisGameObject = Space.Host.ExecutingObject

OnPlayerStandUp = function()
seatPosition = thisGameObject.WorldPosition
teleportPosition = Vector.New(seatPosition.X, seatPosition.Y + 1, seatPosition.Z)
Space.Scene.PlayerAvatar.Teleport(teleportPosition)
end

thisGameObject.Seat.OnPlayerStandUp(OnPlayerStandUp)

```

### OnPlayerSit

void OnPlayerSit(Closure e)

Binds a function to the Seat's On Player Sit event which is fired only on the Player's client

Paramètres

| Nom | Type    | Valeur par défaut |
| --- | ------- | ----------------- |
| e   | Closure | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
e = function()
Space.Log("On Player Sit event")
end

Space.Host.ExecutingObject.Seat.OnPlayerSit(e)

```

**Lua**

```lua
--the below script will check if the player sitting is the owner of the seat
--if they are not, we will remove them from the seat
--(Example: if the seat is a vehicle which the owner wants no one else to use)
--[Requires Seat Component in the GameObject running this script]
--<Note: ID match may not succeed in Editor but will succeed in SS client>

thisGameObject = Space.Host.ExecutingObject

OnPlayerSit = function()
  if Space.Scene.PlayerAvatar.ID ~= thisGameObject.Owner then
    thisGameObject.Seat.UnseatPlayer()
    Space.Log("You do not have permission to sit in this vehicle")
  end
  
end

thisGameObject.Seat.OnPlayerSit(OnPlayerSit)

```

## Propriétés

### Enabled

bool Enabled {get; set; }

Whether the seat component is enabled.

Exemple

**Lua**

```lua
= seatIsEnabled = Space.Host.ExecutingObject.Seat.Enabled

```

**Lua**

```lua
--clicking this object will Enable/Disable it's Seat component
thisGameObject = Space.Host.ExecutingObject
component = thisGameObject.Seat

OnClick = function()
component.Enabled =  not component.Enabled
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)

```

### InUse

bool InUse {get; }

Return that whether the seat is in use.

Exemple

**Lua**

```lua
seatIsInUse = Space.Host.ExecutingObject.Seat.InUse

```

**Lua**

```lua
 --this script will play a looping sound only if someone is using the seat
 --and will stop the sound if someone is not
--(Example: carnival game )
--[Object must contain a Seat component and AudioSource component]

thisGameObject = Space.Host.ExecutingObject


OnUpdate = function()
  if thisGameObject.Seat.InUse then
        if not thisGameObject.Audio.IsPlaying then
        thisGameObject.Audio.Play()
        end
  else
       if thisGameObject.Audio.IsPlaying then
        thisGameObject.Audio.Stop()
        end
  end
end

thisGameObject.Audio.Loop = true
thisGameObject.SubscribeToEvents()
thisGameObject.OnUpdate(OnUpdate) 

```

### PlayerSeated

long PlayerSeated {get; }

Return the ID of the seating player.

Exemple

**Lua**

```lua
player = Space.Host.ExecutingObject.Seat.PlayerSeated

```

### UseSlotID

bool UseSlotID {get; set; }

Return true if uses SlotID

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Seat.UseSlotID = false

```

### SlotID

string SlotID {get; set; }

Return the slot ID of the seat.

Exemple

**Lua**

```lua
seatSlotID = Space.Host.ExecutingObject.Seat.SlotID

```

### ClickableCollider

[SCollider](/docs/fr/scripting/client-scripting-api-reference/components/scollider.md) ClickableCollider {get; set; }

Return the clickable collider.

Exemple

**Lua**

```lua
seatClickableCollider = Space.Host.ExecutingObject.Seat.ClickableCollider

```

### Animation

[SResource](/docs/fr/scripting/client-scripting-api-reference/types/sresource.md) Animation {get; set; }

Return the animation clip.

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Seat.Animation = Space.GetResource("ResourceName")

```

**Lua**

```lua
--the below script will toggle between two seat animations every 30 seconds
--(Example: a couch where the player sitting periodically changes pose)
--[Requires Seat Component in the GameObject running this script]
--[Requires adding 2 animations as "Resources" at the bottom of the Scripting Runtime Component]

thisGameObject = Space.Host.ExecutingObject

anim1 = Space.GetResource("anim1")
anim2 = Space.GetResource("anim2")

thisGameObject.Seat.Animation = anim1
animIndex = 1


AnimationAlternate = function()
  while true do
    Space.Log(thisGameObject.Seat.Animation)
       if animIndex == 1 then
         thisGameObject.Seat.Animation = anim2
         animIndex = 2
        else
          thisGameObject.Seat.Animation = anim1
          animIndex = 1
        end
    
    
    -- next part unseats then seats the player to reflect animation change (its too fast to notice)
    -- we also make sure we are running this part on the specific player sitting (if any), not everyone else
   if thisGameObject.Seat.InUse then 
      if thisGameObject.Seat.PlayerSeated == Space.Scene.PlayerAvatar.ID then
       thisGameObject.Seat.UnseatPlayer()
       thisGameObject.Seat.SitPlayer()
      end
    end
        
     
    Space.Log("yielding") 
    coroutine.yield(5)
    
  end
  
  
  
end

Space.Host.StartCoroutine(AnimationAlternate)

```

### AnimationMale

[SResource](/docs/fr/scripting/client-scripting-api-reference/types/sresource.md) AnimationMale {get; set; }

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Seat.AnimationMale = Space.GetResource("ResourceName")

```

### AnimationFemale

[SResource](/docs/fr/scripting/client-scripting-api-reference/types/sresource.md) AnimationFemale {get; set; }

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Seat.AnimationFemale = Space.GetResource("ResourceName")

```

### GameObject

[SGameObject](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md) GameObject {get; }

Exemple

**Lua**

```lua
theGameObject = Space.Host.ExecutingObject.Seat.GameObject

```
