wiki.sine.space | sinespace

Difference between revisions of "Scripting/SSeat"

From wiki.sine.space
Jump to: navigation, search
(Replaced content with "This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/sseat")
 
Line 1: Line 1:
 
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/sseat
=Members=
+
 
+
{{ScriptFunction|void|SitPlayer|();|Make a player sit.|5=
+
local thisObject=Space.Host.ExecutingObject<br>
+
local seat=thisObject.Children[0].Seat<br>
+
function Seat()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;seat.SitPlayer()<br>
+
end
+
}}
+
 
+
{{ScriptFunction|void|UnseatPlayer|();|Make a player unseat.|5=
+
local thisObject=Space.Host.ExecutingObject<br>
+
local seat=thisObject.Children[0].Seat<br>
+
function UnSeat()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;seat.UnseatPlayer()<br>
+
end
+
}}
+
 
+
{{ScriptFunction|void|OnStandUp|(Closure e);|Binds a function to the Seat's On Stand Up event|5=<pre>
+
e = function()
+
Space.Log("On Stand Up event")
+
end
+
 
+
Space.Host.ExecutingObject.Seat.OnStandUp(e)
+
</pre>
+
}}
+
 
+
{{ScriptFunction|void|OnSit|(Closure e);|Binds a function to the Seat's On Sit event|5=<pre>
+
e = function()
+
Space.Log("On Sit event")
+
end
+
 
+
Space.Host.ExecutingObject.Seat.OnSit(e)
+
</pre>
+
}}
+
 
+
{{ScriptFunction|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|5=<pre>
+
e = function()
+
Space.Log("On Player Stand Up")
+
end
+
 
+
Space.Host.ExecutingObject.Seat.OnPlayerStandUp(e)
+
</pre>|6=
+
<pre>--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)</pre>
+
}}
+
 
+
{{ScriptFunction|void|OnPlayerSit|(Closure e);|Binds a function to the Seat's On Player Sit event which is fired only on the Player's client|5=<pre>
+
e = function()
+
Space.Log("On Player Sit event")
+
end
+
 
+
Space.Host.ExecutingObject.Seat.OnPlayerSit(e)
+
</pre>|6= <pre>
+
--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)</pre>
+
}}
+
 
+
 
+
 
+
=Properties=
+
 
+
{{ScriptFunction|bool|Enabled|{get; set;}|Whether the seat component is enabled.|5=
+
local seat=thisObject.seat<br>
+
Space.Log(seat.Enabled)<br>
+
''--print true.''|6=<pre>--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)</pre>
+
}}
+
 
+
{{ScriptFunction|bool|InUse|(get;)|Return that whether the seat is in use.|5=
+
local thisObject=Space.Host.ExecutingObject<br>
+
local seat=thisObject.Children[0].Seat<br>
+
function InUse()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;local inUse=seat.InUse<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log(inUse)<br>
+
end
+
|6=<pre> --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) </pre>}}
+
 
+
{{ScriptFunction|long|PlayerSeated|(get;);|Return the ID of the seating player.|5=
+
local thisObject=Space.Host.ExecutingObject<br>
+
local seat=thisObject.Children[0].Seat<br>
+
function PlaySeated ()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;local playSeated=seat.PlayerSeated<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log(playSeated)<br>
+
end
+
}}
+
 
+
{{ScriptFunction|bool|UseSlotID|(get;set;);|Return true if uses SlotID|5=
+
local thisObject=Space.Host.ExecutingObject<br>
+
local seat=thisObject.Children[0].Seat<br>
+
function UseSlotID ()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;local useSlotID=seat.UseSlotID<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log(useSlotID)<br>
+
end
+
}}
+
 
+
{{ScriptFunction|string|SlotID|(get;set;);|Return the slot ID of the seat.|5=
+
local thisObject=Space.Host.ExecutingObject<br>
+
local seat=thisObject.Children[0].Seat<br>
+
function SlotID ()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;local slotID=seat.SlotID<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log(slotID)<br>
+
end
+
}}
+
 
+
{{ScriptFunction|SCollider|ClickableCollider|(get;set;);|Return the clickable collider.|5=
+
local thisObject=Space.Host.ExecutingObject<br>
+
local seat=thisObject.Children[0].Seat<br>
+
function ClickableCollider()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;local clickcoll=seat.ClickableCollider<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log(clickcoll.Enabled)<br>
+
end
+
}}
+
 
+
{{ScriptFunction|SResource|Animation|(get;set;);|Return the animation clip.|5=
+
local thisObject=Space.Host.ExecutingObject<br>
+
local seat=thisObject.Children[0].Seat<br>
+
local animation=seat.Animation<br>
+
Space.Log(animation.Name)<br>
+
''--print the name of animation.''
+
|6=<pre>--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)</pre>}}
+
 
+
{{ScriptFunction|SResource|AnimationMale|(get;set;);|Return the animation clip.|5=
+
local thisObject=Space.Host.ExecutingObject<br>
+
local seat=thisObject.Children[0].Seat<br>
+
local animation=seat.AnimationMale<br>
+
Space.Log(animation.Name)<br>
+
''--print the name of animation.''
+
}}
+
 
+
{{ScriptFunction|SResource|AnimationFemale|(get;set;);|Return the animation clip.|5=
+
local thisObject=Space.Host.ExecutingObject<br>
+
local seat=thisObject.Children[0].Seat<br>
+
local animation=seat.AnimationFemale<br>
+
Space.Log(animation.Name)<br>
+
''--print the name of animation.''
+
}}
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 06:23, 19 September 2022

This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/sseat