wiki.sine.space | sinespace

Difference between revisions of "Scripting/SAvatar"

From wiki.sine.space
Jump to: navigation, search
(Replaced content with "This page has moved to: https://docs.sine.space/v/scripting/client-scripting/types/savatar")
 
Line 1: Line 1:
The SAvatar class refers a single player avatar active within the scene. This only contains active players with a valid network connection, and does not include NPCs. ((PlayerAvatar being used below is just an example, as it returns an SAvatar.))
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/types/savatar
 
+
=Members=
+
 
+
 
+
{{ScriptFunction|void|Detach|();|Detaches the avatar from whatever it may be attached to (only works for the player avatar), including chairs, vehicles and so forth.|5=<pre>Space.Scene.PlayerAvatar.Detach()</pre>|6=<pre> --the below scipt makes the player Attach/Detach to/from this object by clicking it
+
--(Example: Seat/Vehicle/Experience etc.. )
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
isAttached = 0
+
 
+
 
+
OnClick = function()
+
 
+
  if isAttached == 0 then
+
    Space.Scene.PlayerAvatar.AttachTo(thisGameObject)
+
    isAttached = 1
+
  elseif isAttached == 1 then
+
    Space.Scene.PlayerAvatar.Detach()
+
    isAttached = 0
+
  end
+
 
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Click to Attach/Detach yourself to/from me"
+
thisGameObject.Clickable.OnClick(OnClick)  </pre>}}
+
 
+
{{ScriptFunction|void|AttachTo|(SGameObject target);|Attaches the player to the target game object, keeping the avatar fixed in its current position/rotation relative to the target object (e.g. for use in Vehicles)|5=<pre>Space.Scene.PlayerAvatar.AttachTo(targetObject)</pre>|6=<pre>--the below scipt makes the player Attach/Detach to/from this object by clicking it
+
--(Example: Seat/Vehicle/Experience etc.. )
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
isAttached = 0
+
 
+
 
+
OnClick = function()
+
 
+
  if isAttached == 0 then
+
    Space.Scene.PlayerAvatar.AttachTo(thisGameObject)
+
    isAttached = 1
+
  elseif isAttached == 1 then
+
    Space.Scene.PlayerAvatar.Detach()
+
    isAttached = 0
+
  end
+
 
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Click to Attach/Detach yourself to/from me"
+
thisGameObject.Clickable.OnClick(OnClick)  </pre>}}
+
 
+
{{ScriptFunction|void|StartFly|();|Puts the avatar into Fly Mode.|5=<pre>Space.Scene.PlayerAvatar.StartFly()</pre>||6= <pre>
+
--the below script teleports the player to a sky location after he clicks
+
--but then immediately puts the character in fly mode so they don't fall back down
+
--(Example: Sky exhibit)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
Space.Scene.PlayerAvatar.Teleport(Vector.New(0,10,0))
+
Space.Scene.PlayerAvatar.StartFly()
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Click me to view our sky exhibit!"
+
thisGameObject.Clickable.OnClick(OnClick) </pre>}}
+
 
+
{{ScriptFunction|void|EndFly|();|Takes the avatar out of Fly Mode.|5=<pre>Space.Scene.PlayerAvatar.EndFly()</pre>|6=<pre>--the below script a player flying in the sky back to the ground
+
--but then immediately end's the character fly mode so they are standing
+
--(Example: Going back down to ground from Sky exhibit)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
Space.Scene.PlayerAvatar.Teleport(Vector.New(0,0,0))
+
Space.Scene.PlayerAvatar.EndFly()
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Click me to go back to the ground!"
+
thisGameObject.Clickable.OnClick(OnClick) </pre>}}
+
 
+
{{ScriptFunction|SGameObject|FindBone|(string bone);|Retrieves the specified bone.|5=
+
<b>-- Best used with non humanoid models</b><br>
+
local bone = Space.Scene.PlayerAvatar.FindBone("Hips/Spine/Chest/LeftShoulder"); -- Gets the bone by path<br>
+
Space.Log(bone.Name); -- Prints the retrieved bones name, which will match the last name in the path specified.<br>
+
 
+
<b>or</b>
+
 
+
<b>-- Best used with humanoid models</b><br>
+
local bone = Space.Scene.PlayerAvatar.FindBone("LeftShoulder"); -- Gets bone by UnityEngine.HumanTrait.BoneName[]<br>
+
Space.Log(bone.Name); -- Prints the bone name of the corresponding search parameter, which when using a default avatar, it will print "LeftShoulder"<br>
+
 
+
--[[<br>
+
<b>UnityEngine.HumanTrait.BoneName[]</b>
+
 
+
<b>Body</b>: Hips, Spine, Chest, UpperChest<br>
+
<b>Head</b>: Neck, Jaw, Head, LeftEye, RightEye<br>
+
 
+
<b>Left Arm</b>: LeftShoulder, LeftUpperArm, LeftLowerArm, LeftHand<br>
+
<b>Left Leg</b>: LeftUpperLeg, LeftLowerLeg, LeftFoot, LeftToes<br>
+
 
+
<b>Right Arm</b>: RightShoulder, RightUpperArm, RightLowerArm, RightHand<br>
+
<b>Right Leg</b>: RightUpperLeg, RightLowerLeg, RightFoot, RightToes<br>
+
 
+
<b>Left Hand (Thumb)</b>: LeftThumbProximal, LeftThumbIntermediate, LeftThumbDistal<br>
+
<b>Left Hand (Index)</b>: LeftIndexProximal, LeftIndexIntermediate, LeftIndexDistal<br>
+
<b>Left Hand (Middle)</b>: LeftMiddleProximal, LeftMiddleIntermediate, LeftMiddleDistal<br>
+
<b>Left Hand (Ring)</b>: LeftRingProximal, LeftRingIntermediate, LeftRingDistal<br>
+
<b>Left Hand (Little)</b>: LeftLittleProximal, LeftLittleIntermediate, LeftLittleDistal<br>
+
 
+
<b>Right Hand (Thumb)</b>: RightThumbProximal, RightThumbIntermediate, RightThumbDistal<br>
+
<b>Right Hand (Index)</b>: RightIndexProximal, RightIndexIntermediate, RightIndexDistal<br>
+
<b>Right Hand (Middle)</b>: RightMiddleProximal, RightMiddleIntermediate, RightMiddleDistal<br>
+
<b>Right Hand (Ring)</b>: RightRingProximal, RightRingIntermediate, RightRingDistal<br>
+
<b>Right Hand (Little)</b>: RightLittleProximal, RightLittleIntermediate, RightLittleDistal<br>
+
]]|6=<pre> --this script will set your avatar's "right hand" as parent of this object
+
--this way this object will be a child of your right hand and therefore move with it
+
--(Example: clicking on a gun to equip it)
+
 
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
 
+
RightHand = Space.Scene.PlayerAvatar.FindBone("RightHand")
+
thisGameObject.SetParent(RightHand)
+
thisGameObject.LocalPosition = Vector.New(0,0,0) -- resetting position to match hand
+
 
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip="Click to Equip "
+
thisGameObject.Clickable.OnClick(OnClick) </pre>}}
+
 
+
 
+
{{ScriptFunction|void|ResetOutfit|();|Reset current outfit. (white-label only)|5=<pre>local Space.Scene.PlayerAvatar.ResetOutfit()</pre>|6=<pre>--Clicking this object will reset player avatar's outfit
+
thisObject = Space.Host.ExecutingObject
+
thisPlayer = Space.Scene.PlayerAvatar
+
 
+
OnClick = function()
+
thisPlayer.ResetOutfit()
+
end
+
 
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>
+
}}
+
 
+
{{ScriptFunction|void|Register|(string username, string password, string email);|Allow a guest to register.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
avatar.Register("MyName","MyPassword","MyEmail",false,function ()
+
    Space.Log("Success!")
+
end,function ()
+
    Space.Log("OnError!!")
+
end)</pre>
+
}}
+
 
+
{{ScriptFunction|void|LoadOutfit|(int outfitID);|Only works on a white-label deployment due to abuse concerns. Restrictions: The outfit ID needs to be one of the grid template outfits, with all the restrictions that apply to those (i.e. must use either SW content, or content uploaded by a grid admin account).|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
avatar.LoadOutfit(10001)</pre>|6=<pre> --the below script changes the player's outfit into
+
--a pre-defined outfit if they click the object containing the script
+
--(Example: Player clicks on a wardrobe and their outfit changes)
+
--[Only works on white-label deployment]
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
Space.Scene.PlayerAvatar.LoadOutfit(2662469)
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Put on your favourite suit"
+
thisGameObject.Clickable.OnClick(OnClick)</pre>
+
}}
+
 
+
{{ScriptFunction|void|ResetOutfitToTemplate|(int outfitID);|Reset current outfit to a specific template. (white-label only)|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
avatar.ResetOutfitToTemplate(10001)</pre>|6=<pre>--Clicking this object will reset player avatar's outfit to a specific template.
+
thisObject = Space.Host.ExecutingObject
+
thisPlayer = Space.Scene.PlayerAvatar
+
 
+
OnClick = function()
+
thisPlayer.ResetOutfitToTemplate(10001)
+
end
+
 
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>
+
}}
+
 
+
{{ScriptFunction|void|Teleport|(string landmarkName);|Teleport the avatar to the landmark.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
avatar.Teleport("MyLandMark")</pre>|6=<pre>--the below script teleports player to a specific landmark
+
--if they click the object containing it
+
--(Example: A region promotional/advertisement sign)
+
--[You need a landmark in the scene with name "Fashion Section Landmark"
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
Space.Scene.PlayerAvatar.Teleport("Fashion Section Landmark")
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Click me to go to the fashion section!"
+
thisGameObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
{{ScriptFunction|void|Teleport|(SVector position);|Teleport the avatar to certain position.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
avatar.Teleport(Vector.Zero)</pre>|6=<pre>--the below script teleports the player to a sky location after he clicks
+
--but then immediately puts the character in fly mode so they don't fall back down
+
--(Example: Sky exhibit)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
Space.Scene.PlayerAvatar.Teleport(Vector.New(0,10,0))
+
Space.Scene.PlayerAvatar.StartFly()
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Click me to view our sky exhibit!"
+
thisGameObject.Clickable.OnClick(OnClick) </pre>
+
}}
+
 
+
{{ScriptFunction|void|Teleport|(SVector position, SQuaternion rotation);|Teleport the avatar to certain position and rotation.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
avatar.Teleport(Vector.Zero,Quaternion.Identity)</pre>|6=<pre>--Clicking this object will teleport you 2 units forward and make you face the opposite way
+
 
+
thisObject = Space.Host.ExecutingObject
+
thisPlayer = Space.Scene.PlayerAvatar
+
 
+
 
+
OnClick = function()
+
local targetPos = thisPlayer.GameObject.WorldPosition + (thisPlayer.GameObject.Forward * 2)
+
local targetRot = thisPlayer.GameObject.WorldRotation  *  Quaternion.AngleAxis(Vector.Up, 180)
+
thisPlayer.Teleport(targetPos, targetRot)
+
 
+
 
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>
+
}}
+
 
+
{{ScriptFunction|void|Teleport|(int region, SVector position, SQuaternion rotation);|Teleport the avatar to a certain region with certain position and rotation.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
avatar.Teleport(2342341,Vector.Zero,Quaternion.Identity)</pre>|6=<pre>--clicking this object will teleport you to a specific region at a specific position and avatar orientation
+
--you can set the region id, position and rotation at the top of the script
+
 
+
REGION_ID = 100
+
POSITION = Vector.New(0,50,0)
+
ROTATION = Quaternion.Euler(0,180,0)
+
 
+
thisObject = Space.Host.ExecutingObject
+
thisPlayer = Space.Scene.PlayerAvatar
+
 
+
 
+
OnClick = function()
+
thisPlayer.Teleport(REGION_ID, POSITION, ROTATION)
+
 
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>
+
}}
+
 
+
{{ScriptFunction|void|Teleport|(int region);|Teleport the avatar to a certain region.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
avatar.Teleport(2342341)</pre>|6=<pre>
+
--the below script teleports player to another region
+
--if they click the object containing it
+
--(Example: A region promotional/advertisement sign)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
Space.Scene.PlayerAvatar.Teleport(151931)
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Click me to go to our region!"
+
thisGameObject.Clickable.OnClick(OnClick)</pre>
+
}}
+
 
+
{{ScriptFunction|void|SetIKGoal|(string goal, bool positionGoal, float positionStrength, SVector positionTarget, bool rotationGoal, float rotationStrength, SQuaternion rotationTarget
+
);|Set the IK goal to avatar.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
local pos=avatar.FindBone("Chest").WorldPosition
+
avatar.SetIKGoal("Chest",false,0,pos,true,20,Quaternion.Euler(0,60,0))</pre>
+
}}
+
 
+
{{ScriptFunction|void|ClearIKGoal|(string goal);|Clear the IK Goal.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
local pos=avatar.FindBone("Chest").WorldPosition
+
avatar.SetIKGoal("Chest",false,0,pos,true,20,Quaternion.Euler(0,60,0))
+
Space.Host.InvokeDelayed(function ()
+
    avatar.ClearIKGoal("Chest")
+
end,5)
+
'' --will clear after 5 seconds.''</pre>
+
}}
+
 
+
{{ScriptFunction|void|PlayCustomAnimation|(SResource animationClip);|Make the avatar plays custom animation.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
avatar.PlayCustomAnimation(Space.Resources[1])
+
'' --the avatar will play the custom animation if the animation clip was set correctly.''</pre> |6=<pre> --the below scipt makes the player Play/Stop a custom animation when clicking this object
+
--(Example: Dance Machine )
+
--[Required: Place an animation in the first "Resource" in the scripting runtime]
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
isDancing = 0
+
 
+
 
+
OnClick = function()
+
 
+
  if isDancing == 0 then
+
    Space.Scene.PlayerAvatar.StartCustomAnimation(Space.Resources[1])
+
    isDancing = 1
+
  elseif isDancing == 1 then
+
    Space.Scene.PlayerAvatar.StopCustomAnimation()
+
    isDancing = 0
+
  end
+
 
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Click to Start/Stop dancing"
+
thisGameObject.Clickable.OnClick(OnClick)  </pre>
+
}}
+
 
+
{{ScriptFunction|void|StopCustomAnimation|();|Make the avatar stops playing custom animation.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
avatar.PlayCustomAnimation(Space.Resources[1])
+
avatar.StopCustomAnimation()</pre>|6=<pre> --the below scipt makes the player Play/Stop a custom animation when clicking this object
+
--(Example: Dance Machine )
+
--[Required: Place an animation in the first "Resource" in the scripting runtime]
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
isDancing = 0
+
 
+
 
+
OnClick = function()
+
 
+
  if isDancing == 0 then
+
    Space.Scene.PlayerAvatar.StartCustomAnimation(Space.Resources[1])
+
    isDancing = 1
+
  elseif isDancing == 1 then
+
    Space.Scene.PlayerAvatar.StopCustomAnimation()
+
    isDancing = 0
+
  end
+
 
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Click to Start/Stop dancing"
+
thisGameObject.Clickable.OnClick(OnClick)  </pre>
+
}}
+
 
+
 
+
 
+
{{ScriptFunction|void|OnAvatarReload|(Closure o);|This event will be called when the avatar gets loaded.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
avatar.OnAvatarReload(function ()
+
    Space.Log(avatar.OutfitID)
+
end)</pre>|6=<pre>--this script ensures the avatar is still animating after their avatar gets reloaded
+
thisPlayer = Space.Scene.PlayerAvatar
+
theAnimation = Space.GetResource("The Animation") --add animation to resources in Scripting Runtime
+
wasAnimated = true --you'll need to set this according to the situation, its true now for example's sake
+
 
+
 
+
ResetDance = function()
+
if wasAnimated then
+
  thisPlayer.PlayCustomAnimation(theAnimation)
+
end
+
 
+
end
+
thisPlayer.OnAvatarReload(ResetDance)</pre>
+
}}
+
 
+
{{ScriptFunction|void|SynchroniseState|();|Synchronise avatar's state to network.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
avatar.SynchroniseState()</pre>
+
}}
+
 
+
 
+
 
+
{{ScriptFunction|bool|OnAvatarSkeletonReload|(Closure o);|This event will be called when the avatar skeleton gets loaded.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
Space.Log(avatar.BlockJump)
+
avatar.OnAvatarSkeletonReload(function ()
+
    Space.Log(avatar.OutfitID)
+
end)</pre>|6=<pre>--this script ensures the avatar is still animating after their avatar's skeleton gets reloaded
+
thisPlayer = Space.Scene.PlayerAvatar
+
theAnimation = Space.GetResource("The Animation") --add animation to resources in Scripting Runtime
+
wasAnimated = true --you'll need to set this according to the situation, its true now for example's sake
+
 
+
 
+
ResetDance = function()
+
if wasAnimated then
+
  thisPlayer.PlayCustomAnimation(theAnimation)
+
end
+
 
+
end
+
thisPlayer.OnAvatarSkeletonReload(ResetDance)</pre>
+
}}
+
 
+
=Properties=
+
{{ScriptFunction|string|Username|{ get; }|Returns the avatar's current username (note: this can be changed by players for a small fee)|5=<pre>playerUsername = Space.Scene.PlayerAvatar.Username</pre>|6= <pre> --this script, once clicked, will get all avatars in the scene
+
--and print their Username(including self)
+
--(Example: scoreboards/radars/scanners/game machines)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
allAvatars = Space.Scene.AllAvatars
+
 
+
        for var=1, #allAvatars do
+
    local Username = allAvatars[var].Username
+
    Space.Log("Username: " .. Username)
+
        end
+
 
+
end
+
 
+
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Click to print all avatars' Username"
+
thisGameObject.Clickable.OnClick(OnClick) </pre>}}
+
 
+
{{ScriptFunction|string|Title|{ get; }|Returns the avatar's current title|5=<pre>playerTitle = Space.Scene.PlayerAvatar.Title</pre>|6=<pre> --this script, once clicked, will get all avatars in the scene
+
--and print their Title and Username(including self)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
allAvatars = Space.Scene.AllAvatars
+
 
+
        for var=1, #allAvatars do
+
    local Username = allAvatars[var].Username
+
    local Title = allAvatars[var].Title
+
    Space.Log(Title .. " " .. Username)
+
        end
+
 
+
end
+
 
+
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Click to print all avatars' Titles and Username"
+
thisGameObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
{{ScriptFunction|long|ID|{ get; }|Returns the avatar's user ID, please note if you store these, this is a 'long' value not a 'int'.|5=<pre>playerID = Space.Scene.PlayerAvatar.ID</pre>|6=<pre>--this script, once clicked, will get all avatars in the scene
+
--and print their ID(including self)
+
--(Example: scoreboards/radars/scanners/game machines)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
allAvatars = Space.Scene.AllAvatars
+
 
+
        for var=1, #allAvatars do
+
    local ID = allAvatars[var].ID
+
    Space.Log("ID: " .. ID)
+
        end
+
 
+
end
+
 
+
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Click to print all avatars' ID"
+
thisGameObject.Clickable.OnClick(OnClick) </pre>}}
+
 
+
{{ScriptFunction|SGameObject|GameObject|{ get; }|Returns a reference to avatar's GameObject|5=<pre>playerObject = Space.Scene.PlayerAvatar.GameObject</pre>|6=<pre>--Clicking this object will teleport you 2 units forward and make you face the opposite way
+
 
+
thisObject = Space.Host.ExecutingObject
+
thisPlayer = Space.Scene.PlayerAvatar
+
 
+
 
+
OnClick = function()
+
local targetPos = thisPlayer.GameObject.WorldPosition + (thisPlayer.GameObject.Forward * 2)
+
local targetRot = thisPlayer.GameObject.WorldRotation  *  Quaternion.AngleAxis(Vector.Up, 180)
+
thisPlayer.Teleport(targetPos, targetRot)
+
 
+
 
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
{{ScriptFunction|bool|BlockMovement|{ get;set; }|If set to True, avatar's movement will be blocked|5=<pre>Space.Scene.PlayerAvatar.BlockMovement = true</pre>|6=<pre> --the below scipt makes this object a boundary area where any user entering it
+
--will be blocked from movement for 10 seconds, then the object will release controls and
+
--destry itself after that
+
--(Example: freezing trap)
+
--[This object's collider needs to be set as IsTrigger (Please read about OnTriggerStart for troubleshooting)]
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
FrozenTime = 0.0
+
 
+
OnTriggerStart = function(TriggerStarter)
+
  if TriggerStarter.Root.Avatar ~= nil then
+
    if TriggerStarter.Root.Avatar.Username == Space.Scene.PlayerAvatar.Username then
+
      Space.Scene.PlayerAvatar.BlockMovement = true
+
    end
+
  end
+
end
+
 
+
OnTriggerStay = function(TriggerStayer)
+
  if TriggerStayer.Root.Avatar ~= nil then
+
    if TriggerStayer.Root.Avatar.Username == Space.Scene.PlayerAvatar.Username then
+
      FrozenTime = FrozenTime + Space.DeltaTime
+
        if FrozenTime > 20 then
+
        Space.Scene.PlayerAvatar.BlockMovement = false
+
        thisGameObject.Destroy()
+
        end
+
    end
+
  end
+
end
+
 
+
thisGameObject.SubscribeToEvents()
+
thisGameObject.OnTriggerStart(OnTriggerStart)
+
thisGameObject.OnTriggerStay(OnTriggerStay)
+
</pre>}}
+
 
+
{{ScriptFunction|bool|Guest|{ get; }|Returns True if avatar is guest|5=<pre>Space.Log(Space.Scene.PlayerAvatar.Guest)</pre>|6=<pre>--this script will make this object non-clickable for guest players
+
 
+
thisObject = Space.Host.ExecutingObject
+
thisPlayer = Space.Scene.PlayerAvatar
+
 
+
OnClick = function()
+
Space.Log("Do Something")
+
end
+
 
+
if not thisPlayer.Guest then --if player is not guest
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)
+
end</pre>}}
+
 
+
{{ScriptFunction|SGameObject|Skeleton|{ get; }|Returns a reference to avatar's skeleton GameObject|5=<pre>avSkeleton = Space.Scene.PlayerAvatar.Skeleton</pre>|6=
+
<pre>--clicking this object will replace your avatar's animator controller (found on the skeleton)
+
thisObject = Space.Host.ExecutingObject
+
thisPlayer = Space.Scene.PlayerAvatar
+
 
+
customController = Space.GetResource("animcont")
+
 
+
 
+
OnClick = function()
+
thisPlayer.Skeleton.Animator.Controller = customController
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
{{ScriptFunction|bool|IsAttached|{ get; }|Returns True if avatar is Attached|5=<pre>Space.Log(Space.Scene.PlayerAvatar.isAttached)</pre>}}
+
 
+
{{ScriptFunction|bool|IsGrounded|{ get; }|Returns True if avatar is Grounded|5=<pre>Space.Log(Space.Scene.PlayerAvatar.isGrounded)</pre>}}
+
 
+
{{ScriptFunction|float|JumpHeight|{ get;set; }|How high the avatar's jump is|5=<pre>Space.Scene.PlayerAvatar.JumpHeight = 20</pre>|6= <pre> --the below scipt makes the object give the player triple jump height
+
--once it's clicked, and then returns them to original jump height after 10 seconds
+
--(Example: Triple Jump Height Powerup )
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
originalJumpHeight = Space.Scene.PlayerAvatar.JumpHeight
+
 
+
TripleJumpHeightCoroutine = function()
+
Space.Scene.PlayerAvatar.JumpHeight = originalJumpHeight * 3
+
coroutine.yield(10)
+
Space.Scene.PlayerAvatar.JumpHeight = originalJumpHeight
+
end
+
 
+
 
+
OnClick = function()
+
Space.Host.StartCoroutine(TripleJumpHeightCoroutine)
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Triple JumpHeight Powerup!"
+
thisGameObject.Clickable.OnClick(OnClick) 
+
</pre>}}
+
 
+
{{ScriptFunction|bool|Loaded|{ get; }|Returns true if avatar is Loaded|5=<pre>Space.Log(Space.Scene.PlayerAvatar.Loaded)</pre>|6=<pre>--this script will wait for a joining avatar to load first before making it play an animation
+
--(otherwise that animation may be reset if played before load is complete)
+
 
+
NewJoinAnimation = Space.GetResource("The Animation")
+
 
+
OnPlayerJoin = function(NewAvatar)
+
 
+
    Space.Host.StartCoroutine(function()
+
     
+
      while not NewAvatar.Loaded do coroutine.yield(0) end --makes it wait
+
Space.Log("yes")   
+
      NewAvatar.PlayCustomAnimation(NewJoinAnimation) --at this point Loaded is True
+
      end)
+
     
+
 
+
end
+
 
+
 
+
Space.Scene.OnPlayerJoin(OnPlayerJoin)</pre>}}
+
 
+
{{ScriptFunction|float|MovementSpeed|{ get;set; }|How fast the avatar's movement is|5=<pre>Space.Scene.PlayerAvatar = 20</pre>|6=<pre> --the below scipt makes the object give the player triple movement speed
+
--once it's clicked, and then returns them to original speed after 10 seconds
+
--(Example: Triple Speed Powerup (vatar running race))
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
TripleSpeedCoroutine = function()
+
local originalSpeed = Space.Scene.PlayerAvatar.MovementSpeed
+
Space.Scene.PlayerAvatar.MovementSpeed = originalSpeed * 3
+
coroutine.yield(10)
+
Space.Scene.PlayerAvatar.MovementSpeed = originalSpeed
+
 
+
end
+
 
+
 
+
OnClick = function()
+
Space.Host.StartCoroutine(TripleSpeedCoroutine)
+
end
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Triple Speed Powerup!"
+
thisGameObject.Clickable.OnClick(OnClick)  </pre>}}
+
 
+
{{ScriptFunction|long|OutfitID|{ get; }|Returns the current outfit ID of the avatar|5=<pre>avOutfit = Space.Scene.PlayerAvatar.OutfitID</pre>}}
+
 
+
{{ScriptFunction|bool|BlockRun|{ get;set; }|Returns true if the avatar could run.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
Space.Log(avatar.BlockRun)
+
avatar.BlockRun=true
+
'' --Now the avatar cannot run anymore.''</pre>|6=<pre>--this script will block a player's run ability when entering trigger collider and release it when leaving
+
--[Requires this object to have a "Trigger" collider]
+
 
+
thisObject = Space.Host.ExecutingObject
+
thisPlayer = Space.Scene.PlayerAvatar
+
 
+
OTS = function(gameObject)
+
  if gameObject.Avatar ~= nil and thisPlayer == gameObject.Avatar then
+
    thisPlayer.BlockRun = true
+
  end
+
end
+
 
+
OTE = function(gameObject)
+
  if gameObject.Avatar ~= nil and thisPlayer == gameObject.Avatar then
+
  thisPlayer.BlockRun = false
+
  end
+
end
+
 
+
thisObject.OnTriggerStart(OTS)
+
thisObject.OnTriggerExit(OTE)</pre>
+
}}
+
 
+
{{ScriptFunction|bool|BlockFly|{ get;set; }|Return true if the avatar could fly.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
Space.Log(avatar.BlockFly)
+
avatar.BlockFly=true
+
'' --Now the avatar cannot fly anymore.''</pre>|6=<pre>--this script will block a player's fly ability when entering trigger collider and release it when leaving
+
--[Requires this object to have a "Trigger" collider]
+
 
+
thisObject = Space.Host.ExecutingObject
+
thisPlayer = Space.Scene.PlayerAvatar
+
 
+
OTS = function(gameObject)
+
  if gameObject.Avatar ~= nil and thisPlayer == gameObject.Avatar then
+
    thisPlayer.BlockFly = true
+
  end
+
end
+
 
+
OTE = function(gameObject)
+
  if gameObject.Avatar ~= nil and thisPlayer == gameObject.Avatar then
+
  thisPlayer.BlockFly = false
+
  end
+
end
+
 
+
thisObject.OnTriggerStart(OTS)
+
thisObject.OnTriggerExit(OTE)</pre>
+
}}
+
 
+
{{ScriptFunction|bool|BlockCrouch|{ get;set; }|Return true if the avatar could crouch.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
Space.Log(avatar.BlockCrouch)
+
avatar.BlockCrouch=true
+
'' --Now the avatar cannot crouch anymore.''</pre>|6=<pre>--this script will block a player's crouch ability when entering trigger collider and release it when leaving
+
--[Requires this object to have a "Trigger" collider]
+
 
+
thisObject = Space.Host.ExecutingObject
+
thisPlayer = Space.Scene.PlayerAvatar
+
 
+
OTS = function(gameObject)
+
  if gameObject.Avatar ~= nil and thisPlayer == gameObject.Avatar then
+
    thisPlayer.BlockCrouch = true
+
  end
+
end
+
 
+
OTE = function(gameObject)
+
  if gameObject.Avatar ~= nil and thisPlayer == gameObject.Avatar then
+
  thisPlayer.BlockCrouch = false
+
  end
+
end
+
 
+
thisObject.OnTriggerStart(OTS)
+
thisObject.OnTriggerExit(OTE)</pre>
+
}}
+
 
+
{{ScriptFunction|bool|BlockJump|{ get;set; }|Return true if the avatar could jump.|5=<pre>local avatar=Space.Scene.PlayerAvatar
+
Space.Log(avatar.BlockJump)
+
avatar.BlockJump=true
+
'' --Now the avatar cannot jump anymore.''</pre>|6=<pre>--this script will block a player's jump ability when entering trigger collider and release it when leaving
+
--[Requires this object to have a "Trigger" collider]
+
 
+
thisObject = Space.Host.ExecutingObject
+
thisPlayer = Space.Scene.PlayerAvatar
+
 
+
OTS = function(gameObject)
+
  if gameObject.Avatar ~= nil and thisPlayer == gameObject.Avatar then
+
    thisPlayer.BlockJump= true
+
  end
+
end
+
 
+
OTE = function(gameObject)
+
  if gameObject.Avatar ~= nil and thisPlayer == gameObject.Avatar then
+
  thisPlayer.BlockJump= false
+
  end
+
end
+
 
+
thisObject.OnTriggerStart(OTS)
+
thisObject.OnTriggerExit(OTE)</pre>
+
}}
+
 
+
 
+
{{ScriptFunction|SGameObject|LockObject|{ get; }|5=<pre></pre>
+
}}
+
 
+
 
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 07:51, 19 September 2022

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