e=function()Space.Log("On Stand Up event")endSpace.Host.ExecutingObject.Seat.OnStandUp(e)
OnSit
void OnSit (Closure e)
Binds a function to the Seat's On Sit event
Parameter
Type
Description
e=function()Space.Log("On Sit event")endSpace.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
Parameter
Type
Description
e=function()Space.Log("On Player Stand Up")endSpace.Host.ExecutingObject.Seat.OnPlayerStandUp(e)
--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.ExecutingObjectOnPlayerStandUp=function()seatPosition = thisGameObject.WorldPositionteleportPosition = Vector.New(seatPosition.X, seatPosition.Y +1, seatPosition.Z)Space.Scene.PlayerAvatar.Teleport(teleportPosition)endthisGameObject.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
Parameter
Type
Description
e=function()Space.Log("On Player Sit event")endSpace.Host.ExecutingObject.Seat.OnPlayerSit(e)
--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.ExecutingObjectOnPlayerSit=function()if Space.Scene.PlayerAvatar.ID ~= thisGameObject.Owner then thisGameObject.Seat.UnseatPlayer() Space.Log("You do not have permission to sit in this vehicle")endendthisGameObject.Seat.OnPlayerSit(OnPlayerSit)
--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.ExecutingObjectOnUpdate=function()if thisGameObject.Seat.InUse thenifnot thisGameObject.Audio.IsPlaying then thisGameObject.Audio.Play()endelseif thisGameObject.Audio.IsPlaying then thisGameObject.Audio.Stop()endendendthisGameObject.Audio.Loop =truethisGameObject.SubscribeToEvents()thisGameObject.OnUpdate(OnUpdate)
PlayerSeated
long PlayerSeatedget
Return the ID of the seating player.
player = Space.Host.ExecutingObject.Seat.PlayerSeated
--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.ExecutingObjectanim1 = Space.GetResource("anim1")anim2 = Space.GetResource("anim2")thisGameObject.Seat.Animation = anim1animIndex =1AnimationAlternate=function()whiletruedo Space.Log(thisGameObject.Seat.Animation)if animIndex ==1then thisGameObject.Seat.Animation = anim2 animIndex =2else thisGameObject.Seat.Animation = anim1 animIndex =1end-- 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 elseif thisGameObject.Seat.InUse thenif thisGameObject.Seat.PlayerSeated == Space.Scene.PlayerAvatar.ID then thisGameObject.Seat.UnseatPlayer() thisGameObject.Seat.SitPlayer()endend Space.Log("yielding") coroutine.yield(5)endendSpace.Host.StartCoroutine(AnimationAlternate)