|
|
(3 intermediate revisions by the same user not shown) |
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>
| + | |
− | 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>
| + | |
− | 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(seatPosition)
| + | |
− | 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.''
| + | |
− | }}
| + | |
− | | + | |
− | {{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>
| + | |
− | local inUse=seat.InUse<br>
| + | |
− | Space.Log(inUse)<br>
| + | |
− | end
| + | |
− | }}
| + | |
− | | + | |
− | {{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>
| + | |
− | local playSeated=seat.PlayerSeated<br>
| + | |
− | 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>
| + | |
− | local useSlotID=seat.UseSlotID<br>
| + | |
− | 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>
| + | |
− | local slotID=seat.SlotID<br>
| + | |
− | 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>
| + | |
− | local clickcoll=seat.ClickableCollider<br>
| + | |
− | 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}}
| + | |