diff options
author | nat-goodspeed <nat@lindenlab.com> | 2024-09-24 07:28:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 07:28:44 -0400 |
commit | 1175288a3c685310dbbf7fdd46d7deae0b0bf92d (patch) | |
tree | 84fd4d186169807c4da1c0c352d9be92f1e63227 /indra/newview/scripts/lua/test_animation.lua | |
parent | 0ee1106faccf90c883d8b9ffc522a341659742ed (diff) | |
parent | 9036e4582cec1893016bd692293ec1c0135f7112 (diff) |
Merge pull request #2534 from secondlife/release/luau-scripting
Add Lua scripting to develop, behind feature flag
Diffstat (limited to 'indra/newview/scripts/lua/test_animation.lua')
-rw-r--r-- | indra/newview/scripts/lua/test_animation.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/indra/newview/scripts/lua/test_animation.lua b/indra/newview/scripts/lua/test_animation.lua new file mode 100644 index 0000000000..37e7254a6c --- /dev/null +++ b/indra/newview/scripts/lua/test_animation.lua @@ -0,0 +1,32 @@ +LLInventory = require 'LLInventory' +LLAgent = require 'LLAgent' + +-- Get 'Animations' folder id (you can see all folder types via LLInventory.getFolderTypeNames()) +animations_id = LLInventory.getBasicFolderID('animatn') +-- Get animations from the 'Animation' folder (you can see all folder types via LLInventory.getAssetTypeNames()) +anims = LLInventory.collectDescendentsIf{folder_id=animations_id, type="animatn"}.items + +local anim_ids = {} +for key in pairs(anims) do + table.insert(anim_ids, key) +end + +if #anim_ids == 0 then + print("No animations found") +else + -- Start playing a random animation + math.randomseed(os.time()) + local random_id = anim_ids[math.random(#anim_ids)] + local anim_info = LLAgent.getAnimationInfo(random_id) + + print("Starting animation locally: " .. anims[random_id].name) + print("Loop: " .. anim_info.is_loop .. " Joints: " .. anim_info.num_joints .. " Duration " .. tonumber(string.format("%.2f", anim_info.duration))) + LLAgent.playAnimation{item_id=random_id} + + -- Stop animation after 3 sec if it's looped or longer than 3 sec + if anim_info.is_loop == 1 or anim_info.duration > 3 then + LL.sleep(3) + print("Stop animation.") + LLAgent.stopAnimation(random_id) + end +end |