wiki.sine.space | sinespace

Difference between revisions of "Scripting/SSeat"

From wiki.sine.space
Jump to: navigation, search
Line 146: Line 146:
 
Space.Log(animation.Name)<br>
 
Space.Log(animation.Name)<br>
 
''--print the name of animation.''
 
''--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=
 
{{ScriptFunction|SResource|AnimationMale|(get;set;);|Return the animation clip.|5=

Revision as of 15:58, 11 July 2021

Members

SitPlayer

void SitPlayer ();

Make a player sit.

local thisObject=Space.Host.ExecutingObject

local seat=thisObject.Children[0].Seat
function Seat()
    seat.SitPlayer()

end


UnseatPlayer

void UnseatPlayer ();

Make a player unseat.

local thisObject=Space.Host.ExecutingObject

local seat=thisObject.Children[0].Seat
function UnSeat()
    seat.UnseatPlayer()

end


OnStandUp

void OnStandUp (Closure e);

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

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

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

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

Space.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.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)

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

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

Space.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.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)


Properties

Enabled

bool Enabled {get; set;}

Whether the seat component is enabled.

local seat=thisObject.seat

Space.Log(seat.Enabled)

--print true.


InUse

bool InUse (get;)

Return that whether the seat is in use.

local thisObject=Space.Host.ExecutingObject

local seat=thisObject.Children[0].Seat
function InUse()
    local inUse=seat.InUse
    Space.Log(inUse)

end


PlayerSeated

long PlayerSeated (get;);

Return the ID of the seating player.

local thisObject=Space.Host.ExecutingObject

local seat=thisObject.Children[0].Seat
function PlaySeated ()
    local playSeated=seat.PlayerSeated
    Space.Log(playSeated)

end


UseSlotID

bool UseSlotID (get;set;);

Return true if uses SlotID

local thisObject=Space.Host.ExecutingObject

local seat=thisObject.Children[0].Seat
function UseSlotID ()
    local useSlotID=seat.UseSlotID
    Space.Log(useSlotID)

end


SlotID

string SlotID (get;set;);

Return the slot ID of the seat.

local thisObject=Space.Host.ExecutingObject

local seat=thisObject.Children[0].Seat
function SlotID ()
    local slotID=seat.SlotID
    Space.Log(slotID)

end


ClickableCollider

SCollider ClickableCollider (get;set;);

Return the clickable collider.

local thisObject=Space.Host.ExecutingObject

local seat=thisObject.Children[0].Seat
function ClickableCollider()
    local clickcoll=seat.ClickableCollider
    Space.Log(clickcoll.Enabled)

end


Animation

SResource Animation (get;set;);

Return the animation clip.

local thisObject=Space.Host.ExecutingObject

local seat=thisObject.Children[0].Seat
local animation=seat.Animation
Space.Log(animation.Name)

--print the name of animation.


--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 AnimationMale (get;set;);

Return the animation clip.

local thisObject=Space.Host.ExecutingObject

local seat=thisObject.Children[0].Seat
local animation=seat.AnimationMale
Space.Log(animation.Name)

--print the name of animation.


AnimationFemale

SResource AnimationFemale (get;set;);

Return the animation clip.

local thisObject=Space.Host.ExecutingObject

local seat=thisObject.Children[0].Seat
local animation=seat.AnimationFemale
Space.Log(animation.Name)

--print the name of animation.